File(File parent, String child)
根据 parent 抽象路径名和 child 路径名字符串创建一个新 File 实例。
File(String parent, String child)
根据 parent 路径名字符串和 child 路径名字符串创建一个新 File 实例。这是file类的两个构造方法参数?我不太理解 请高手解释下.
最好举个例子 写出来看看!
根据 parent 抽象路径名和 child 路径名字符串创建一个新 File 实例。
File(String parent, String child)
根据 parent 路径名字符串和 child 路径名字符串创建一个新 File 实例。这是file类的两个构造方法参数?我不太理解 请高手解释下.
最好举个例子 写出来看看!
子文件夹是:def(当然是在abc之下的)
则:File f=new File(new File("d:/abc"),"def");
或:
File f=new File("d:/abc","def");
[code=BatchFile]
public File(String parent,
String child)
根据 parent 路径名字符串和 child 路径名字符串创建一个新 File 实例。
如果 parent 为 null,则创建一个新的 File 实例,这与调用以给定 child 路径名字符串作为参数的单参数 File 构造方法效果一样。 否则,parent 路径名字符串用于表示目录,child 路径名字符串用于表示目录或文件。如果 child 路径名字符串是绝对路径名,则用与系统有关的方式将它转换为一个相对路径名。如果 parent 是空字符串,则通过将 child 转换为抽象路径名,并根据与系统有关的默认目录解析结果来创建新的 File 实例。否则,将每个路径名字符串转换为一个抽象路径名,并根据父抽象路径名解析子抽象路径名。
参数:
parent - 父路径名字符串
child - 子路径名字符串
抛出:
NullPointerException - 如果 child 为 null
[/code]
* new File(new File(),fileName)
* new File(filePath,fileName)
* @author WangYanCheng
*
*/
public class FileTest {
/**
* @param args args
* @throws Exception exception
*/
public static void main(String[] args) throws Exception {
java.io.File file1 = new java.io.File("C:\\", "file_1.txt");
boolean canCreate = file1.createNewFile();
if (canCreate) {
java.io.File file2 = new java.io.File(file1, "file1_file2.txt");
System.out.println(file1.getPath() + "\n---" + file2.getPath());
}
}
}
File f=new File("E:/test");
f.mkdir();
创建文件
File f1=new File("E:/test/test.txt");
f1.createNewFile();
File f=new File("E:/test");
f.mkdir();
创建文件
File f1=new File("E:/test/test.txt");
f1.createNewFile();
五楼的说的 就是这样,楼主还有什么不明白吗?
建议看看JAVA 的API