博客
关于我
Day53.File类的实例化 -Java常用类、集合、IO#
阅读量:334 次
发布时间:2019-03-04

本文共 1118 字,大约阅读时间需要 3 分钟。

File类的实例化

在这里插入图片描述

在这里插入图片描述

/*   File类的使用     1. File类的一个对象,代表一个文件或一个文件目录(俗称: 文件夹)     2. File类声明在java.io包下     3. File类中涉及到关于文件或文件目录的创建、删除、重命名、修改时间、文件大小等方法,        并未涉及到写入或读取文件内容的操作。如果需要读取或写入文件内容。就必须使用IO流来完成     4. 后续File类的对象常会作为参数传递到流的构造器中,指明读取或写入的"终点"。 */public class FileTest {       /*    1. 如何创建File的实例        File(String filePath)        File(String parentPath,String childPath)        File(File parentPath,String childPath)    2.    相对路径:相较于某个路径下,指明的路径。    绝对路径:包含盘符在内的路径或文件目录的路径        说明:    IDEA中:    如果大家开发使用Junit中的单元测试方法测试,相对路径即为当前Module下。    如果使用main()测试,相对路径即为当前的Project下。    Eclipse中:    不管使用单元测试方法还是使用main()测试,相对路径都是Project下。            3.路径分隔符    windows: \\    unix、url: /     */    @Test    public void test1(){           //构造器1:        File file1 = new File("Hello.txt");//相对于当前module        File file2 = new File("D:\\Note\\src\\com\\he.txt");        System.out.println(file1);        System.out.println(file2);        //构造器2:        File file3 = new File("D:\\Note\\src","com");        System.out.println(file3);        //构造器3:        File file4 = new File(file3,"he.txt");        System.out.println(file4);    }}

转载地址:http://cuoq.baihongyu.com/

你可能感兴趣的文章
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
查看>>
No module named 'crispy_forms'等使用pycharm开发
查看>>
No module named 'pandads'
查看>>
No module named cv2
查看>>
No module named tensorboard.main在安装tensorboardX的时候遇到的问题
查看>>
No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
查看>>
No new migrations found. Your system is up-to-date.
查看>>
No qualifying bean of type XXX found for dependency XXX.
查看>>
No qualifying bean of type ‘com.netflix.discovery.AbstractDiscoveryClientOptionalArgs<?>‘ available
查看>>
No resource identifier found for attribute 'srcCompat' in package的解决办法
查看>>
no session found for current thread
查看>>
No static resource favicon.ico.
查看>>
no such file or directory AndroidManifest.xml
查看>>
No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
查看>>