代码如下:
import java.io.*;
public class IoTest {
public static void main(String[] args) throws Exception {
File parent = new File("D:");
String child ="1"+File.separator+"1.txt";
File f = new File(parent, child);
f.createNewFile();
}}
我想在D盘创建个1文件夹,然后在里面建个1.txt文件,为什么显示:
Exception in thread "main" java.io.IOException: 系统找不到指定的路径。
at java.io.WinNTFileSystem.createFileExclusively(Native Method)
at java.io.File.createNewFile(File.java:883)
at a.IoTest.main(IoTest.java:9)
求高手讲解,感激不尽!!
import java.io.*;
public class IoTest {
public static void main(String[] args) throws Exception {
File parent = new File("D:");
String child ="1"+File.separator+"1.txt";
File f = new File(parent, child);
f.createNewFile();
}}
我想在D盘创建个1文件夹,然后在里面建个1.txt文件,为什么显示:
Exception in thread "main" java.io.IOException: 系统找不到指定的路径。
at java.io.WinNTFileSystem.createFileExclusively(Native Method)
at java.io.File.createNewFile(File.java:883)
at a.IoTest.main(IoTest.java:9)
求高手讲解,感激不尽!!
public class IoTest {
public static void main(String[] args) throws Exception {
File parent = new File("D:");
String child =File.separator+"1.txt";
File f = new File(parent, child);
f.createNewFile();
}}
String child ="1"+File.separator+"1.txt";
File f = new File(parent, child);
这两行代码,拼接出来的路径不是d:\1.txt 是d:1\1.txt所以无法找到指定路径
File path = new File(root,"1");
if(!path.exists()) path.mkdirs();
File file = new File(path,"1.txt");
boolean success = file.createNewFile();