public class test {
public static String readFileContent(String fileName) {
File file = new File(fileName);
BufferedReader reader = null;
StringBuffer sbf = new StringBuffer();
try {
reader = new BufferedReader(new FileReader(file));
String tempStr;
while ((tempStr = reader.readLine()) != null) {
sbf.append(tempStr);
}
reader.close();
System.out.println(sbf.toString());
return sbf.toString();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
return sbf.toString();
}
//将字符写入文件
public static void writetoFile(String str) throws IOException {
Java读取一个文件内容并写入另一个文件
最新推荐文章于 2023-01-02 16:57:39 发布
这篇博客介绍了如何使用Java的BufferedReader读取文件内容,并通过FileOutputStream将内容写入另一个文件。作者提到已经实现了一个基本的功能,并计划日后详细总结输入输出的使用方法。
摘要由CSDN通过智能技术生成