Reading One Line from a File in UTF-16 Format

Viewed 302

I have some files generated from a script that provide information about various computers. The txt files are in UTF-8, however, there is one line that is in UTF-16 format. How should I go about reading this line from the file?

P.S. I'm trying to write a program to parse out all of these files and recompile them into one collective .csv file.

I have tried reading the file with a bufferedReader and Scanner, however this one line is the only one I am having trouble with. Most of the code I have found online for reading UTF-16 is for the entire file, which is not completely in UTF-16.

//How the line looks when opened in Notepad.

S e r i a l N u m b e r     5 C G 8 X X X X X X

//How the line looks when opened in Notepad++ with "nul" values in between each character.

S e r i a l N u m b e r     

 5 C G 8 X X X X X X

My code can pick up parts of the string, but the format of it is on multiple lines and Java doesn't recognize the characters in between each letter or number.

1 Answers

You can try like this.

File infile = new File("/someFileInutf16.txt");
FileInputStream inputStream = new FileInputStream(infile);
 Reader in = new InputStreamReader(inputStream, "UTF-16");
Related