【java】读写文件
2024-10-07 16:48:31
不要吐槽我为啥不写try,catch。
默认的相对路径是在工作空间的目录下。
如图
import java.io.*;
import java.util.*; public class filerw {
public static void main(String []args) throws IOException { String pathname = "in.txt";
FileReader reader = new FileReader(pathname);
BufferedReader br = new BufferedReader(reader);
String tmpString;
while( (tmpString = br.readLine())!= null) {
System.out.println(tmpString);
} File file = new File("out.txt"); FileWriter fw = new FileWriter(file.getName(),true);
String data = " This is a test";
fw.write(data);
fw.close(); FileWriter fw1 = new FileWriter(file);
BufferedWriter bw = new BufferedWriter(fw1);
bw.write(data);
bw.close(); }
}
最新文章
- 360浏览器下载excel问题解决方式
- C++小项目:directx11图形程序(七):modelclass
- Python 处理数据库返回结果
- ul li 下的元素内容垂直居中
- SVN和git的使用(附github的简单玩法)
- 从客户端中检测到有潜在危险的Request.Form值 的解决方法
- 【Stage3D学习笔记续】真正的3D世界(五):粒子特效
- 优化器的使用oracle ---explain plan
- Linux 软件源设置
- Python开篇
- 【Java SE】如何用Java实现反转排序
- Tutorial 02_熟悉常用的HDFS操作
- springboot国际化
- 第8章 枚举类&;注解
- vim学习、各类插件配置与安装【转】
- Centos 密钥登录系统
- bzoj 1390: [Ceoi2008]Fence
- js模拟自动点击事件
- 【转载】IEEE754 学习总结
- CF 570 D. Tree Requests