创建:
第一种:import org.testng.annotations.Test;
import java.io.File;
import java.io.IOException;
public class createFile {
public static void main(String[] args) {
}
@Test
public void create1(){
String pathname = "D://file1.txt";
File file = new File(pathname);
try {
file.createNewFile();
System.out.println("6");
}catch (IOException e){
throw new RuntimeException(e);
}
}
}
第二种:
import org.testng.annotations.Test;
import java.io.File;
import java.io.IOException;
public class createFile {
public static void main(String[] args) {
}
@Test
public void create2(){
File parenFile = new File("D:\\");
String fileNane = "file2.txt";
File file = new File(parenFile,fileNane);
try {
file.createNewFile();
System.out.println("6");
}catch (IOException e){
throw new RuntimeException(e);
}
}
}
第三种:
import org.testng.annotations.Test;
import java.io.File;
import java.io.IOException;
public class createFile {
public static void main(String[] args) {
@Test
public void create3(){
String parentPath = "d:\\";
String filePath = "file3.txt";
File file = new File(parentPath,filePath);
try {
file.createNewFile();
System.out.println("6");
}catch (IOException e){
throw new RuntimeException(e);
}
}
文件信息查询:
import org.testng.annotations.Test;标签:java,file,System,查询,文件夹,File,import,public,out From: https://www.cnblogs.com/llas666/p/16863587.html
import java.io.File;
public class find {
public static void main(String[] args){
}
@Test
public void lnfo(){
File file = new File("D:\\file 1.txt");
System.out.println("文件名:"+file.getName());
System.out.println("文件绝对路径:"+file.getAbsolutePath());
System.out.println("文件父路径:"+file.getParent());
System.out.println("文件大小:"+file.length());
System.out.println("文件是否存在:"+file.exists());
System.out.println("是否是文件:"+file.isFile());
System.out.println("是否是目录:"+file.isDirectory());
}
}