

💟💟前言
友友们大家好,我是你们的小王同学😗😗
今天给大家带来的是java io流——创建文件
希望能给大家带来有用的知识
觉得小王写的不错的话 麻烦动动小手 点赞👍 收藏⭐ 评论📄
小王的主页:小王同学🚗
小王的gitee:小王同学🏩
小王的github:小王同学💦
目录🧔🏼
文件在程序中是以流的形势来操作的

流:数据在数据源(文件)和程序(内存)之间经历的路径
输入流:数据从数据源(文件)到程序(内存)的路径
输出流::数据从程序(内存)到数据源(文件)路径
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("创建成功~");
-
-
- }
![]()
这时候我们在e盘找到了我们刚才创建的txt文本
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();
- }
- }
![]()
以上就是小王同学带给大家的三种创建文件的方式了
文件在开发工作中需求还是很多的 还是要好好学!