当前位置: 首页 > news >正文

Java-IO流-15

文件操作

文件创建

package com.edu.file;import org.junit.jupiter.api.Test;import java.io.File;
import java.io.IOException;public class Demo01 {public static void main(String[] args) {}@Test//方式1public void create01(){String filePath = "D:\\new1.txt";File file = new File(filePath);try {file.createNewFile();} catch (IOException e) {throw new RuntimeException(e);}System.out.println("创建成功");}@Test//方式二public void create02(){File file = new File("d:\\"); //父String fileName = "new2.txt";//子File file1 = new File(file,fileName);try {file1.createNewFile(); //真正创建} catch (IOException e) {throw new RuntimeException(e);}}@Test//方式三public void crete03(){String parentPath = "d:\\";String sonPath = "new3.txt";File file = new File(parentPath,sonPath);try {file.createNewFile();} catch (IOException e) {throw new RuntimeException(e);}System.out.println("创建成功");}
}

获取文件信息
 

   //获取文件信息public void info(){//先创建文件对象File file = new File("d:\\new3.txt");//调用相应方法得到对应信息System.out.println("文件名字:"+file.getName());System.out.println("文件绝对路径"+file.getAbsolutePath());System.out.println("文件父目录"+file.getParent());System.out.println("文件大小"+file.length());System.out.println("文件是否存在"+file.exists());System.out.println("是不是一个文件"+file.isFile());System.out.println("是不是一个目录"+file.isDirectory());}

http://www.lryc.cn/news/275505.html

相关文章:

  • java中使用redis
  • Mongodb的可重试读操作
  • 2024年1月2日-1月7日(ue5底层渲染+ue arpg+项目需求)
  • MySQL中的视图和触发器
  • uView-UI v2.x常见问题整理
  • MBTI职业性格测试 28题(免费版)
  • Springcloud 微服务实战笔记 Ribbon
  • CSS基础笔记-04cascade-specificity-inheritance
  • Spring应用的部署与管理
  • B端产品经理学习-需求挖掘
  • 整数规划基本原理
  • 秋招复习之堆
  • 算法训练营Day36(贪心-重叠区间)
  • 如何利用Oracle官方网站不登录账号下载和安装非最新版本的JDK(版本自由选择)
  • 税法相关的基础知识
  • ListNode 2487. 从链表中移除节点,单调栈的应用
  • vue3中pdf打印问题处理
  • 如何向嵌入式设备中添加tcpdump工具
  • 伦茨科技Apple Find My认证芯片-ST17H6x芯片
  • uni-app 前后端调用实例 基于Springboot 数据列表显示实现
  • python渗透工具编写学习笔记:10、网络爬虫基础/多功能编写
  • Python武器库开发-武器库篇之子域名扫描器开发(四十一)
  • 通俗易懂的15个Java Lambda表达式案例
  • 十七:爬虫-JS逆向(上)
  • How to implement anti-crawler strategies to protect site data
  • 王国维的人生三境界,这一生至少当一次傻瓜
  • Jmeter二次开发实操问题汇总(JDK问题,jar包问题)
  • 网络安全B模块(笔记详解)- 数字取证
  • 阿里云服务器8080端口安全组开通图文教程
  • vmlinux, vmlinux.bin, bzImage; cmake的find_package(Clang)新增了哪些变量( 比较两次记录的所有变量差异)