java核心技术卷2-1.6 操作文件

操作文件

2018年11月23日 星期五
下午1:16
简述大致方法,纯属个人笔记

Path absolute = Paths.get(“myprog”, “conf”, “user.properties”)
get方法把路径用系统分隔符链接 或使用system.getproperty(“File.separator”) 或File.separator

System.getProperty()的参数总结:
java.version Java运行时环境版本
java.vendor Java运行时环境供应商
java.vendor.url Java供应商的 URL
java.home Java安装目录
java.vm.specification.version Java虚拟机规范版本
java.vm.specification.vendor Java虚拟机规范供应商
java.vm.specification.name Java虚拟机规范名称
java.vm.version Java虚拟机实现版本
java.vm.vendor Java虚拟机实现供应商
java.vm.name Java虚拟机实现名称
java.specification.version Java运行时环境规范版本
java.specification.vendor Java运行时环境规范供应商
java.specification.name Java运行时环境规范名称
java.class.version Java类格式版本号
java.class.path Java类路径
java.library.path 加载库时搜索的路径列表
java.io.tmpdir 默认的临时文件路径
java.compiler 要使用的 JIT 编译器的名称
java.ext.dirs 一个或多个扩展目录的路径
os.name 操作系统的名称
os.arch 操作系统的架构
os.version 操作系统的版本
file.separator 文件分隔符(在 UNIX 系统中是“/”)
path.separator 路径分隔符(在 UNIX 系统中是“:”)
line.separator 行分隔符(在 UNIX 系统中是“/n”)
user.name 用户的账户名称
user.home 用户的主目录
user.dir 用户的当前工作目录

java.nio.file.Paths

static Path get(String first, String … more) 通过给定的多个字符串创造路径

java.nio.file.Path

Path resolve(Path other)
Path resolve(String other) 若other是绝对路径,返回other;否则链接两个路径
Path resolveSibling(Path other)
Path resolveSibling(String other) 若other是绝对路径,返回other;否则返回this父路径与other的链接
Path relativize(Path other) 返回对other进行解析的相对路径
Path normalize() 移除诸如.和…的冗余路径元素
Path toAbsolutePath() 返回绝对路径
Path getParent() 返回父路径
Path getFileName() 返回文件名
Path getRoot() 返回根
toFile()

java.io.File

Path toPath()

java.nio.file.File

static byte[] readAllBytes(Path path)
static List readAllLines(Path path, Charset charset)
static Path writer(Path path, byte[] contents, OpenOption… options)
static Path writer(Path path, Iterable<?extends CharSequence> contents, OpenOption options)
static InputStream newInputStream(Path path, OpenOption… options)
static OutputStream newOutputStream(Path path, OpenOption… options)
static BufferedReader newBufferedReader(Path path, Charset charset)
static BufferedWriter newBufferedWriter(Path path, Charset charset, OpenOption… options)

static Path copy(Path from, Path to, CopyOption… option)
static Path move(Path from, Path to, CopyOption… option) from复制/移动到to,并返回to
static void delete(Path path)
static boolean deleteIfExists(Path path) 删除文件或空目录,第一种不存在时抛出异常,第二种返回false

static Path createFile(Path path, FileAttribute<?>… attrs)
static Path createDirectory(Path path, FileAttribute<?>… attrs)
static Path createDirectories(Path path, FileAttribute<?>… attrs) 创建文件或目录,createDirectories会创建中间目录
static Path createTempFile(String prefix, String suffix, FileAttribute<?>… attrs)
static Path createTempFile(Path parentDir, String prefix, String suffix, FileAttribute<?>… attrs)
static Path createTempFile(String prefix, FileAttribute<?>… attrs)
static Path createTempFile(Path parentDir, String prefix, FileAttribute<?>… attrs)在适合临时文件的位置或父目录中,创建一个临时文件或目录,返回创建的路径

static boolean exsist(Path path)
static boolean isHiddern(Path path)
static boolean isReadable(Path path)
static boolean isWriter(Path path)
static boolean isExecutable(Path path)
static boolean isRegularFile(Path path)
static boolean isDirectory(Path path)
static boolean isSybolicLink(Path path)
检查文件的属性
static long size(Path path) 获取字节数
A readAttributes(Path path, Class type, LinkOption… options) 读取类型为A的文件属性

java.nio.file.attribute.BasicFileAttributes

FileTime CreationTime()
FileTime lastAccessTime()
FileTime lastModifiedTime()
boolean isRegularFile()
boolean isDirectory()
boolean isSymbolicLink()
long size()
Object filekey()
获取请求属性的值

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值