博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Java如何创建临时文件并打印File各种属性
阅读量:7071 次
发布时间:2019-06-28

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

临时文件使用完毕需要自己清理,避免沾满磁盘空间。

public static void main(String[] args) throws IOException {        File temp = File.createTempFile("test", ".archive");        System.out.println(temp.getName()); // test3055590609638838031.archive        System.out.println(temp.getPath()); // /var/folders/2x/65r35n150q118b_chsszlh1c0000gn/T/test6559503323010508065.archive        System.out.println(temp.getUsableSpace()); // 34223104000        System.out.println(temp.getFreeSpace()); // 44578095104        System.out.println(temp.getTotalSpace()); // 500068036608        System.out.println(temp.getAbsolutePath()); // /var/folders/2x/65r35n150q118b_chsszlh1c0000gn/T/test6559503323010508065.archive//        System.out.println(temp.getAbsoluteFile());        System.out.println(temp.getCanonicalPath()); // /private/var/folders/2x/65r35n150q118b_chsszlh1c0000gn/T/test6559503323010508065.archive//        System.out.println(temp.getCanonicalFile());        System.out.println(temp.getParent()); // /var/folders/2x/65r35n150q118b_chsszlh1c0000gn/T//        System.out.println(temp.getParentFile());        System.out.println(temp.delete()); // true                System.out.println(File.pathSeparator); // :                System.out.println(File.separator); // /    }复制代码

转载于:https://juejin.im/post/5ab4be51f265da237e09a93c

你可能感兴趣的文章
Python文件遍历二种方法
查看>>
GUN 的汇编语法
查看>>
java.lang.VerifyError: Inconsistent stackmap frames at branch target
查看>>
sqlite 判断表中是否包含 某个字段
查看>>
freemarker序列的拆分
查看>>
angularjs基本执行流程
查看>>
线段树 + 区间更新: HDU 4893 Wow! Such Sequence!
查看>>
再探vim经常使用命令
查看>>
[BZOJ 1066][SCOI2007]蜥蜴
查看>>
platform_device与platform_driver
查看>>
sql中update,alter,modify,delete,drop的区别和使用(整理)(转)
查看>>
Enabling Active Directory Authentication for VMWare Server running on Linux《转载》
查看>>
MySql性能优化相关
查看>>
Android学习笔记——Intents 和 Intent Filters(二)
查看>>
收藏的Android很好用的组件或者框架。
查看>>
SQL Server 数据库文件 4 点注意
查看>>
赛马题(转)
查看>>
网页的背景图片代码
查看>>
SURF算法与源码分析、下
查看>>
高速排序算法
查看>>