java 读取文本文件内容,转换成string

时间:2022-11-18 14:43:00

 

     StringBuffer buffer = new StringBuffer();
        BufferedReader bf= new BufferedReader(new FileReader("Z:\\Users\\caixl\\Desktop\\新建文本文档.txt"));
        String s = null;
        while((s = bf.readLine())!=null){//使用readLine方法,一次读一行
            buffer.append(s.trim());
        }
String xml
= buffer.toString();