Solved

reading text file problem

Posted on 2006-07-06
13
255 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

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 75 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 50 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This video teaches viewers about errors in exception handling.
Suggested Courses

751 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