基础编码
import java.io.File;
public class Test {
public static void main (String[] args) {
File file = new File("D:/myword" , "test.txt" );
if (file.exists()) {
file.delete();
System.out.println("文件已删除" );
} else {
try {
file.createNewFile();
System.out.println("文件已创建" );
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
import java.io.File;
public class Test {
public static void main (String[] args) {
File file = new File("D:/mywork" , "work.txt" );
if (file.exists()) {
String name = file.getName();
long length = file.length();
boolean hidden = file.isHidden();
System.out.println("文件名称:" + name);
System.out.println("文件长度:" + length);
System.out.println("该文件是隐藏文件吗?" + hidden);
} else {
System.out.println("该文件不存在" );
}
}
}
from: http://blog.csdn.net/xuezhisdc/article/details/52197319