I have written following code to read system generated file for scheduled task i.e. SchedLgU.Txt
File f = new File("C:\\WINDOWS\\Tasks\\SchedLgU.Txt");
FileInputStream fstream = new FileInputStream(f);
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line="";
do{
line = br.readLine();
System.ou开发者_开发知识库t.println(line);
} while(br.readLine()!=null);
I am getting some junk value with characters with boxes.
Is there any different format I have to define?
Well, you're using InputStreamReader
without specifying a character encoding - so it will always use the platform default encoding. It looks like this file is in UTF-16 (at least on my box). Just pass that encoding to the InputStreamReader
constructor to read the file properly.
Trying it with your test program, that seems to work. Note that there's no point using a DataInputStream
if you're just going to wrap it in an InputStreamReader
- just pass the FileInputStream
directly to the InputStreamReader
constructor:
BufferedReader br = new BufferedReader(new InputStreamReader(fstream, "UTF-16"));
精彩评论