java对IO的操作
2024-09-04 15:27:13
import java.io.*; public class HelloWorld { //Main method.
public static void main(String[] args) {
CreateFile();
ListFileName();
ShowSeparator();
} //Create a file.
//Judge that the file exists.
public static void CreateFile() {
File f = new File("d:\\hello.xt");
try {
if (!f.exists()) {
f.createNewFile();
System.out.println("File created successfully.");
} else {
f.delete();
f.createNewFile();
System.out.println("File exists! File is created again.");
}
} catch (Exception e) {
e.printStackTrace();
}
} //Get file name of all for loop.
public static void ListFileName()
{
String _fileName="D:"+File.separator;
File _fileObj=new File(_fileName);
File[] _fileList=_fileObj.listFiles();
for(File _file : _fileList)
{
System.out.println(_file.getName()+"\n");
}
} //Separator is applyed to different system. For example,windows,linux and so on.
public static void ShowSeparator()
{
System.out.println("file:"+File.separator+"\n"+"path:"+File.pathSeparator);
}
} 本文由fang_beny原创,转载请注明出处。
最新文章
- 【BZOJ】【2565】最长双回文串
- YouTube上的版权保护
- requirejs 打包参数
- Symmetry(对称轴存在问题)
- cf B. Fox Dividing Cheese
- BZOJ 2599 Race(树分治)
- vc 基于对话框多线程编程实例——线程之间的通信
- SQL CRUD 简单查询
- 原生ajax实现http请求
- FastJson对于JSON格式字符串、JSON对象及JavaBean之间的相互转换
- 用LSTM分类 MNIST
- python 实现多层目录文件查找
- vue-输入框change事件并获取值
- MySQL---DDL+DQL---(四)
- apache beam ElasticSearchIO 遇到异常后job中断执行 自己定制beam IO
- [git与github]__git与github简单了解
- 什么是PAGELATCH和PAGEIOLATCH
- TSQL:判断某较短字符串在较长字符串中出现的次数。
- JDBC 与 Bean Shell的使用(二)获取值,并且断言
- 自己搞了20万张图片100个分类,tensorflow训练23万次后。。。。。。
热门文章
- Kwickserver
- 怎样设置gephi可画大规模网络图形
- JAVA反射机制--怎么不受泛型束缚给数组赋值
- windows pip源
- Linux网络编程中tcp_server和tcp_client函数的封装
- Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'.
- hdu4930 Fighting the Landlords(模拟 多校6)
- 【Excle数据透视表】如何在Excle中使用数据鼠标拖放
- JavaScript Array pop(),shift()函数
- ORACLE截取字符串