1

I am reading the below line from an .sql file using Apache File Utilities.

INSERT INTO tablename (MESSAGE) VALUE('transfer of £[%1] to the following [%2]:');

but after reading i get the below:

'transfer of �[%1] to the following [%2]:'

problem: *£* is read in as �

I am using the below Code to read the file line by line :

LineIterator it = FileUtils.lineIterator(file, "UTF-8");
while (it.hasNext()) {
                lineCount++;
                line = it.nextLine();
                System.out.println(line);

Print Line shows as : transfer of �[%1] to the following [%2]:'

when i see the variable watch in Netbeans it shows that char as \ufffd

Am i reading it with wrong encoding ?

Is there is any encoding i can use for SQL queries to be read ?

Wills
  • 491
  • 8
  • 20
  • It's plausible there is an issue reading the file correctly. It's also plausible there's an error in *displaying* the value. How do you know the value is incorrect? How are you displaying it? – Duncan Jones Apr 29 '13 at 12:30

1 Answers1

1

It sounds like you've selected the wrong encoding for your file. I was able to reproduce your issue by trying to read an ISO 8859-1 encoded file with your code example.

You need to determine the encoding of your text file and adjust your charset accordingly. E.g.

LineIterator it = FileUtils.lineIterator(file, Charsets.ISO_8859_1.name());

Sadly, determining the encoding is not something you can do automatically. You need to be explicitly told what the encoding is.

Community
  • 1
  • 1
Duncan Jones
  • 67,400
  • 29
  • 193
  • 254
  • @Dunncan i agree with you duncan. is there is a way to identify the encoding ? Mine is a .sql file – Wills Apr 29 '13 at 12:44
  • @Wills No, as explained in my final paragraph, you cannot figure this out programmatically with certainty. Some programs can guess for you, but it's only a guess. – Duncan Jones Apr 29 '13 at 12:47
  • thanks for the help can you please let me know any resource which i can use to get the encoding corrected - if in handy ? – Wills Apr 29 '13 at 12:50