• JAVA IO流——创建文件


     

     💟💟前言

    友友们大家好,我是你们的小王同学😗😗

    今天给大家带来的是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对象

    代码附上:👼🏼

    1. public static void create01(){
    2. //方式1 newFile(String Pathname) //根据路径构建一个File对象
    3. String filePath="e:\\wxz.txt";
    4. File file=new File(filePath);
    5. try {
    6. file.createNewFile();
    7. } catch (IOException e) {
    8. e.printStackTrace();
    9. }
    10. System.out.println("创建成功~");
    11. }

     这时候我们在e盘找到了我们刚才创建的txt文本

    new File(File parent,String child) //根据父目录文件+子路径构建

    代码附上:👼🏼

    1. public static void create02(){
    2. //根据父目录文件+子路径构建
    3. File parentfile=new File("e:\\"); //父路径
    4. String filename="wxz02.txt";
    5. //这里的file对象,在java程序中只是一个对象而已
    6. File file=new File(parentfile,filename);
    7. try {
    8. file.createNewFile();
    9. } catch (IOException e) {
    10. e.printStackTrace();
    11. }
    12. System.out.println("创建成功");
    13. }

     创建成功~

    new File (String parent,String child) //根据父目录+子路径构建

    代码附上:👼🏼

    1. public static void create03(){
    2. //根据父目录+子路径构建
    3. String parentPath="e:\\";
    4. String fileName="wxz03.txt";
    5. File file=new File(parentPath,fileName);
    6. try {
    7. file.createNewFile();
    8. System.out.println("创建成功!");
    9. } catch (IOException e) {
    10. e.printStackTrace();
    11. }
    12. }

     以上就是小王同学带给大家的三种创建文件的方式了

    文件在开发工作中需求还是很多的 还是要好好学!

  • 相关阅读:
    【QT】ROS2 Humble联合使用QT教程
    新浪财经行情中心的对象 Market_Center
    避免项目延期,有效推进项目进度的4大关键方法
    Opencv
    Dubbo服务控制台Dubbo Admin配置
    sqlflow简介,在线版:使用sqlflow,本地版:在windows上安装sqlflow
    React(2)-函数组件
    vue 分段进度条组件
    线程安全
    【React 源码】(四)reconciler 运作流程
  • 原文地址:https://blog.csdn.net/weixin_59796310/article/details/126310143