Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

reading text file problem

Posted on 2006-07-06
13
Medium Priority
?
264 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
  • 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
Technology Partners: 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!

 

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
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…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
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

824 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