Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

reading text file problem

Posted on 2006-07-06
13
Medium Priority
?
260 Views
Last Modified: 2010-03-31
hi,

i need to read text files and store into database. i can read but i have problem with this turkish characters; ŞşİıĞğ. So i cant store properly. what should i do?

thanks...
0
Comment
Question by:komputer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
  • 3
13 Comments
 
LVL 92

Expert Comment

by:objects
ID: 17049534
use utf8 encoding to store it
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17049535
You need to use UTF8 in the db
0
 
LVL 92

Expert Comment

by:objects
ID: 17049537
generally you can specify the encoding oin your connection string
0
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

 

Author Comment

by:komputer
ID: 17049560
my code to read txt file below;

          try {
            BufferedReader in = new BufferedReader(new FileReader(fileName));
            String data = "";
            while ((str =in.readLine()) != null) {
               
                    data += str;
                  }
            }
            in.close();
        } catch (IOException e) {
              
        }

where should i change?
sorry i am new at java.



0
 
LVL 92

Accepted Solution

by:
objects earned 300 total points
ID: 17049575
change it to:

            BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(fileName), charset));

where charset is the encoding ujsed in the text file

you'll also need to specify ewncoding when saving to database
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 200 total points
ID: 17049633
If you want to save a file as a string it would be more efficient to do it more like below.


      public static String fileToString(String fileName) {
            Reader in = null;
            try {
                  File f = new File(fileName);
                  StringBuffer sb = new StringBuffer((int)f.length());
                  char[] charBuf = new char[BUF_SIZE];
                  in = new InputStreamReader(new FileInputStream(f), "UTF8");
                  int charsRead = -1;
                  while ((charsRead = in.read(charBuf, 0, BUF_SIZE)) > -1) {
                        sb.append(charBuf, 0, charsRead);
                  }
                  return sb.toString();
            }
            catch(IOException e){
                  e.printStackTrace();
                  return null;
            }
            finally {
                  try { in.close(); } catch(IOException e) { /* ignore */ }
            }
      }
0
 

Author Comment

by:komputer
ID: 17049681
  >>you'll also need to specify ewncoding when saving to database

could you send me the needed connection string please?

0
 
LVL 92

Expert Comment

by:objects
ID: 17049690
depends on your database
0
 

Author Comment

by:komputer
ID: 17049788
for oracle?
0
 
LVL 92

Expert Comment

by:objects
ID: 17049819
don't think you need anything special for oracle :)
0
 

Author Comment

by:komputer
ID: 17049910
thanks guys...
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17049978
:-)
0
 

Author Comment

by:komputer
ID: 17050021
justice for all ;)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question