Java创建文件和文件夹
2024-09-29 21:24:56
java代码:
import java.io.*;//导入所需的包
public class IOTest {//类
public static void main(String[] args){//主程序,程序入口
File file=new File("D:\\Qiju_Li");
if(!file.exists()){//如果文件夹不存在
file.mkdir();//创建文件夹
}
try{//异常处理
//如果Qiju_Li文件夹下没有Qiju_Li.txt就会创建该文件
BufferedWriter bw=new BufferedWriter(new FileWriter("D:\\Qiju_Li\\Qiju_Li.txt"));
bw.write("Hello I/O!");//在创建好的文件中写入"Hello I/O"
bw.close();//一定要关闭文件
}catch(IOException e){
e.printStackTrace();
}
}
}
最新文章
- curl发送get和post请求
- Android使用SAX解析XML(2)
- ExpandableListView二级列表
- C#中动态读写App.config配置文件
- Requirements of an SAP system administrator
- openstack neutron网络主机节点网口配置 liberty版本之前的
- 典型的 SQL 注入过程(转)
- kettle不能正常自动获取字段
- Linux curses库使用
- WINFORM窗体里使用网页控件的一些办法
- iOS之网络编程
- pipe管道
- golang 线程与通道
- OO电梯调度
- 如何用 Python 模糊搜索文件
- rosetta geometric constraint file(用于match和design)
- liunx存储管理之基础知识
- 地图上道路编号中的G S X Y
- vijos 1128 N个数选K个数 (DFS )
- ubuntu上安装ftp