Solved

reading text file problem

Posted on 2006-07-06
13
248 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Suggested Solutions

Title # Comments Views Activity
oracle 11g 23 107
ejb example issues 3 25
ejb entity bean example issue 2 16
Eclipse Java import and method not resolved 4 48
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This video teaches viewers about errors in exception handling.

861 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