📄 example7_5.java
字号:
/*
* Example7_5.java
*
* Created on 2006年9月15日, 下午6:03
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package example7_5;
import java.io.*;
import java.net.*;
/**
*
* @author Administrator
*/
public class Example7_5 {
/** Creates a new instance of Example7_5 */
public Example7_5() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException{
// TODO code application logic here
File file = new File("hehe");
if(!file.exists()) //测试此抽象路径名表示的文件或目录是否存在
{
file.mkdir();//创建此抽象路径名指定的目录
}
File nextFile = new File(file,"ming");//创建此抽象路径名指定的目录,包括创建必需但不存在的父目录
if(!nextFile.exists())
nextFile.mkdirs();
System.out.println(nextFile.getParent());//测试此抽象路径名表示的文件是否是一个目录
if(nextFile.isDirectory())
{
File newFile = new File(nextFile,"ming.txt");
if(!newFile.exists())
{
newFile.createNewFile();
System.out.println(newFile.getName());
System.out.println(newFile.getAbsoluteFile());
}
for(int i=0;i <5;i++)
{
//当且仅当不存在具有此抽象路径名指定的名称的文件时,原地创建由此抽象路径名指定的一个新的空文件
File listFile = new File(nextFile,"ming"+i+".txt");
if(!listFile.exists())
{
listFile.createNewFile();
}
}
//返回由此抽象路径名所表示的目录中的文件和目录的名称所组成字符串数组
String[] list = nextFile.list();
for(int j = 0;j<list.length;j++)
{
System.out.println(list[j]);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -