import java.io.File;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
public class FileTest {
public static void main(String[] args) throws IOException {
File file = new File("test.txt");
if (!file.exists()) {
System.out.println("正在创建");
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("文件创建成功");
}
else {
System.out.println("找到文件名为test的文本文件");
if(file.isFile() && file.canRead())
{
System.out.println("正在读取文件信息");
}
System.out.println(file.getName());
System.out.println(file.getAbsolutePath());
System.out.println(file.isHidden());
System.out.println(file.length());
long temptime = file.lastModified();
Date date = new Date();
DateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
System.out.println(df.format(temptime));
// System.out.println(temptime);
/*SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date(temptime);
String time = sdf.format(date);
System.out.println(time);*/
}
}
}
Java 文件操作
最新推荐文章于 2024-06-27 15:25:28 发布