package 使用FILE类;import java.io.*;
import java.util.*;public class TestFileClass {
public static void main(String[] args) {
// Create a File object
File file = new File("D:\\JAVA\\eclipse\\工作区\\简单输入输出\\us.txt");
System.out.println("Does it exist? " + file.exists());
System.out.println("Can it be read? " + file.canRead());
System.out.println("Can it be written? " + file.canRead());
System.out.println("Is it a directory? " + file.isDirectory());
System.out.println("Is it a file? " + file.isFile());
System.out.println("Is it absolute? " + file.isAbsolute());
System.out.println("Is it hidden? " + file.isHidden());
System.out.println("What is its absolute path? " +
file.getAbsolutePath());
try {
System.out.println("What is its canonical path? " +
file.getCanonicalPath());
}
catch (IOException ex) { } System.out.println("What is its name? " + file.getName());
System.out.println("What is its path? " + file.getPath());
System.out.println("When was it last modified? " +
new Date(file.lastModified())); System.out.println("What is the path separator? " +
File.pathSeparatorChar);
System.out.println("What is the name separator? " +
File.separatorChar);
}
}
哪位达人帮小弟看一下这个程序,为什么创建不也不了文件呢,不胜感激啊
import java.util.*;public class TestFileClass {
public static void main(String[] args) {
// Create a File object
File file = new File("D:\\JAVA\\eclipse\\工作区\\简单输入输出\\us.txt");
System.out.println("Does it exist? " + file.exists());
System.out.println("Can it be read? " + file.canRead());
System.out.println("Can it be written? " + file.canRead());
System.out.println("Is it a directory? " + file.isDirectory());
System.out.println("Is it a file? " + file.isFile());
System.out.println("Is it absolute? " + file.isAbsolute());
System.out.println("Is it hidden? " + file.isHidden());
System.out.println("What is its absolute path? " +
file.getAbsolutePath());
try {
System.out.println("What is its canonical path? " +
file.getCanonicalPath());
}
catch (IOException ex) { } System.out.println("What is its name? " + file.getName());
System.out.println("What is its path? " + file.getPath());
System.out.println("When was it last modified? " +
new Date(file.lastModified())); System.out.println("What is the path separator? " +
File.pathSeparatorChar);
System.out.println("What is the name separator? " +
File.separatorChar);
}
}
哪位达人帮小弟看一下这个程序,为什么创建不也不了文件呢,不胜感激啊
解决方案 »
- 关于J2SE的纠结
- 各位长老,谁能给下常用的java 内存泄漏检测工具,加上使用文档最好了
- 32位寄存器扩展为64位
- 我想问下做一个贪吃蛇的程序要用到哪些知识,具体一点的
- 大家一起为奥运出力,看我的奥运倒计时问题出在哪里? (applet,线程的关闭)
- jbuilder中在一个工程中加入一个web module,在src中的java编译后可以自动copy到web-inf\classes目录下,但是src下的xml文件和properties
- 接口輿純虛類有什麼區別?
- 反射的具体步骤是什么啊?
- 关于mysql--给点初学者一点建议吧!
- 新手求大神指导指导一些java基础的东西
- 关于英文系统开发环境中java的中文处理
- 高手都来讨论下
new File是在内存里创建的
extends Object
implements Serializable, Comparable<File>An abstract representation of file and directory pathnames.
f.createNewFile();//创建文件
f.mkdirs();//创建目录
file.createNewFile();//创文件
file.mkdirs;//创目录...
会抛出异常