BufferedReader in = null;
FileInputStream fs = null;
try {
fs = new FileInputStream(new File("C://Users//UserName//workspace//Client//DownloadFileList//1//New Text Document.txt"));
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
List<String> contents=new ArrayList<String>();
try {
in = new BufferedReader(new InputStreamReader(fs,"GBK"));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String line;
try {
while((line = in.readLine())!=null) {
contents.add(line);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
windows创建文本文件默认为ANSI编码,读取文件乱码解决~!
最新推荐文章于 2023-10-30 11:16:19 发布