今天小编就为大家分享一篇Java 读取指定路径的文本文件并返回String的方法,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
如下所示:
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(); } }