如下所示:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
import java.io.*; /** * created by liuyikai on 2016/8/13. */ public class fileutil { public static string loadcontentbypath(string path) throws ioexception { inputstream is = new fileinputstream(path); bufferedreader in = new bufferedreader( new inputstreamreader(is)); stringbuffer buffer = new stringbuffer(); string line = "" ; while ((line = in.readline()) != null ){ buffer.append(line); } return buffer.tostring(); } } |
以上这篇java 读取指定路径的文本文件并返回string的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/blizzardlyk/article/details/52240471