import java.io.File;
import java.io.IOException;
import org.junit.Test;
/**
* 文件及文件夹的操作
*
* @author rhy
* @2017-4-6 下午1:50:51
* @version v1.0
*/
public class FileDemo {
@Test
public void test() {
String filePath = "d://file";
File file = new File(filePath);
if (!file.exists()) {
file.mkdir();
System.out.println("执行完了");
}
}
@Test
public void test1() {
String filePath = "d://file//a.gif";
File file = new File(filePath);
if (!file.exists()) {
try {
file.createNewFile();
System.out.println("执行完了啊");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
import java.io.IOException;
import org.junit.Test;
/**
* 文件及文件夹的操作
*
* @author rhy
* @2017-4-6 下午1:50:51
* @version v1.0
*/
public class FileDemo {
@Test
public void test() {
String filePath = "d://file";
File file = new File(filePath);
if (!file.exists()) {
file.mkdir();
System.out.println("执行完了");
}
}
@Test
public void test1() {
String filePath = "d://file//a.gif";
File file = new File(filePath);
if (!file.exists()) {
try {
file.createNewFile();
System.out.println("执行完了啊");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
注意:创建文件时,必须先创建文件夹