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

来源:互联网 发布:淘宝卖纸巾怎么上架 编辑:程序博客网 时间:2024/05/19 12:16

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]);

  }
 }

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

原创粉丝点击