package com.qst.chapter01;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.FileStore;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
public class NIO2FilesDemo {
public static void main(String[] args) {
try {
// 复制文件
Files.copy(
Paths.get("src\\com\\qst\\chapter01\\NIO2FilesDemo.java"),
new FileOutputStream("a.txt"));
// 判断NIO2FilesDemo.java文件是否为隐藏文件
System.out.println("NIO2FilesDemo.java是否为隐藏文件:"
+ Files.isHidden(Paths
.get("src/com/qst/chapter09/NIO2FilesDemo.java")));
// 一次性读取FilesTest.java文件的所有行
List<String> lines = Files.readAllLines(Paths.get("src", "com",
"qst", "chapter09", "NIO2FilesDemo.java"), Charset
.forName("gbk"));
System.out.println("行数:" + lines.size());
// 判断指定文件的大小
System.out.println("a.txt文件的大小为:" + Files.size(Paths.get("a.txt")));
List<String> poem = new ArrayList<>();
poem.add("使用NIO.2技术");
poem.add("往文件中写内容");
// 直接将多个字符串内容写入指定文件中
Files.write(Paths.get("pome.txt"), poem, Charset.forName("gbk"));
FileStore cStore = Files.getFileStore(Paths.get("C:"));
// 判断C盘的总空间,可用空间
System.out.println("C:共有空间:" + cStore.getTotalSpace());
System.out.println("C:可用空间:" + cStore.getUsableSpace());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
chapter01.zip
需积分: 0 158 浏览量
2023-02-14
09:47:55
上传
评论
收藏 30KB ZIP 举报
田三金金
- 粉丝: 0
- 资源: 1
最新资源
- kernel-devel-3.10.0-1062.21.1.el7.x86-64.rpm
- kernel-3.10.0-1062.21.1.el7.x86-64.rpm
- A2_smvs.zip
- Assignment2(4).ipynb
- 用pytorch框架实现的油井时间序列动态预测的模型,其中包含一些传统的时间序列预测方法 .zip
- TimesNet作为一般时间序列分析强大的基础模型 在长短期预测、插补、异常检测和分类5个主流任务上取得了一致的前沿成果.zip
- 实现结构体序列化和反序列化工具类CSearchive,支持基本类型,C++STL容器以及对象 .zip
- 时间序列遥感变化检测.zip
- 时间序列数据集收集以及数据分析.zip
- 时间序列分析ARIMA预测模型.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈