Thursday, January 16, 2014
android read GBK garbled text file
Look at the code, but so is the GBK files are read, there is garbled, UTF8 no problem, how transcoding, ah, do not understand
public String readFile (File file) {
FileInputStream fis = null;
BufferedInputStream bis = null;
DataInputStream dis = null;
StringBuffer sb = new StringBuffer ();
try {
fis = new FileInputStream (file);
/ / Here BufferedInputStream is added for fast reading.
bis = new BufferedInputStream (fis);
dis = new DataInputStream (bis);
/ / Dis.available () returns 0 if the file does not have more lines.
while (dis.available ()! = 0) {
/ / This statement reads the line from the file and print it to
/ / The console.
sb.append (dis.readLine ());
if (dis.available ()! = 0) {
sb.append ("\ n");
}
}
/ / Dispose all the resources after using them.
fis.close ();
bis.close ();
dis.close ();
} Catch (FileNotFoundException e) {
Log.e (TAG, "File not found", e);
Toast.makeText (this, R.string.file_not_found,
. Toast.LENGTH_SHORT) show ();
return null;
} Catch (IOException e) {
Log.e (TAG, "File not found", e);
Toast.makeText (this, R.string.error_reading_file,
. Toast.LENGTH_SHORT) show ();
return null;
}
return sb.toString ();
}
Reply:
Because when you save the file is to use UTF-8 encoding, so that the need to decode the UIT-8, I hope to help you
Help poke http://vote.blog.csdn.net/blogstaritem/blogstar2013/xiaanming < / a>
Reply:
Upstairs, hello, save me know UTF8, but it is impossible to read the whole file is UTF8 it, the purpose is how to read the file GBK, upstairs can bonbon me, I see little
Reply:
Good deserted ah. . .
Reply:
Themselves, and
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment