java通过file文件流,读取txt文件内容

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

猜你喜欢

转载自blog.csdn.net/weixin_39763930/article/details/116237099
今日推荐