JAVA IO流——创建文件
文件
文件在程序中是以流的形势来操作的
流:数据在数据源(文件)和程序(内存)之间经历的路径
输入流:数据从数据源(文件)到程序(内存)的路径
输出流::数据从程序(内存)到数据源(文件)路经
常用的文件操作
创建文件对象相关构造器和方法
new File(String pathname) //根据路径构建一个File对象
new File(File parent,String child) //根据父目录文件+子路径构建
new File (String parent,String child) //根据父目录+子路径构建
createNewFile 创建新文件
new File(String pathname) //根据路径构建一个File对象
代码附上:
new File(File parent,String child) //根据父目录文件+子路径构建
new File (String parent,String child) //根据父目录+子路径构建
createNewFile 创建新文件
new File(String pathname) //根据路径构建一个File对象
代码附上:
public static void create01(){
//方式1 newFile(String Pathname) //根据路径构建一个File对象
String filePath="e:\\wxz.txt";
File file=new File(filePath);
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("创建成功~");
} new File(File parent,String child) //根据父目录文件+子路径构建
public static void create02(){
//根据父目录文件+子路径构建
File parentfile=new File("e:\\"); //父路径
String filename="wxz02.txt";
//这里的file对象,在java程序中只是一个对象而已
File file=new File(parentfile,filename);
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("创建成功");
} new File (String parent,String child) //根据父目录+子路径构建 public static void create03(){
//根据父目录+子路径构建
String parentPath="e:\\";
String fileName="wxz03.txt";
File file=new File(parentPath,fileName);
try {
file.createNewFile();
System.out.println("创建成功!");
} catch (IOException e) {
e.printStackTrace();
}
}
//根据父目录+子路径构建
String parentPath="e:\\";
String fileName="wxz03.txt";
File file=new File(parentPath,fileName);
try {
file.createNewFile();
System.out.println("创建成功!");
} catch (IOException e) {
e.printStackTrace();
}
}

