windows创建文本文件默认为ANSI编码,读取文件乱码解决~!

    技术2022-05-20  29

     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();    }


    最新回复(0)