欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

文件操作! Java 

程序员文章站 2022-07-15 10:29:45
...
//读文件转成字符串!
	public static String fileToString(String fileName) throws IOException {

		String lineContent = null;// 
		StringBuffer str = new StringBuffer();
		FileReader fr;
		try {
			fr = new FileReader(fileName);
			BufferedReader br = new BufferedReader(fr);//
			lineContent = new String();
			lineContent = br.readLine().trim();
			do {
				str.append(lineContent.trim());
			} while ((lineContent = br.readLine()) != null);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return str.toString();
	}


相关标签: Java