Java 读取文件全部内容

主要代码:

import java.io.File;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;public class Application {public static void main(String[] args) throws IOException {String content = "";StringBuilder builder = new StringBuilder();File file = new File("E:\\hello.txt");InputStreamReader streamReader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8);BufferedReader bufferedReader = new BufferedReader(streamReader);while ((content = bufferedReader.readLine()) != null) builder.append(content);System.out.println(builder.toString());}
}

本文链接:https://my.lmcjl.com/post/14596.html

展开阅读全文

4 评论

留下您的评论.