File类
1.创建文件夹
public static void main(String[] args) {
// TODO Auto-generated method stub
FileTest ft=new FileTest();
String mynewpath=" E:\\filetest"; //单“\”要用“\\”才能显示,“\”是转义字符
ft.newFolder(mynewpath);
}
private void newFolder(String newFolder){
try {
File mypath=new File(newFolder);
if(!mypath.exists()){ //判断目录是否存在,即文件夹
mypath.mkdir(); //不存在,创建新目录,建立目录方法是调用mkdir()方法
}
System.out.println("试试");
} catch (Exception e) {
// TODO Auto-generated catch block
System.out.println("目录已存在 ");
e.printStackTrace();
}
}
2.创建文件
PrintWriter pw = new PrintWriter( new FileWriter( "e:\\filetest\\aa\\问好.txt" ) );
pw.print( "你好" );
pw.close( );
}