java通过file文件流,读取txt文件内容
下面展示 部分代码
。
String path="F:\\test.txt";//文件路径
File file = new File(path); // 要读取以上路径的test.txt文件
System.out.println(file.getName());
byte[] bytes = new byte[1024];
StringBuffer sb = new StringBuffer();
FileInputStream input = new FileInputStream(file);
int len;
while ((len = input.read(bytes)) != -1) {
sb.append(new String(bytes, 0, len));
}
System.out.println(sb.toString());
input.close();