IO读取文件内容【含汉字】

    技术2022-05-20  52

    String charsetName = "GBK";  String path = "D:/keyword.txt";  File file = new File(path);  InputStreamReader insReader = new InputStreamReader(new FileInputStream(file), charsetName);  int c = 0;  while((c = insReader.read())!=-1){       System.out.println((char)c);  }  insReader.close();

     

    ///

    public static void main(String[] args) throws Exception {  File fileFrom = new File("D:/keyword.txt");//如果你用到的sturts2标签的 可以不用写  FileInputStream fis = new FileInputStream(fileFrom);// 读取你写的文件  byte[] content = new byte[fis.available()];  fis.read(content);  fis.close();  String str = new String(content, "utf-8");  String[] str2=str.split(",");  for (int i = 0; i < str2.length; i++) {   System.out.println(str2[i]);

      } }

    //待完成中…………………………


    最新回复(0)