总结
其他的内容都可以按照路线图里面整理出来的知识点逐一去熟悉,学习,消化,不建议你去看书学习,最好是多看一些视频,把不懂地方反复看,学习了一节视频内容第二天一定要去复习,并总结成思维导图,形成树状知识网络结构,方便日后复习。
这里还有一份很不错的《Java基础核心总结笔记》,特意跟大家分享出来
目录:
部分内容截图:
@Test
void testCreateFile1() throws IOException {
String fileName = “D:\data\test\newFile.txt”;
Path path = Paths.get(fileName);
// 使用newBufferedWriter创建文件并写文件
// 这里使用了try-with-resources方法来关闭流,不用手动关闭
try (BufferedWriter writer =
Files.newBufferedWriter(path, StandardCharsets.UTF_8)) {
writer.write(“Hello World -创建文件!!”);
}
//追加写模式
try (BufferedWriter writer =
Files.newBufferedWriter(path,
StandardCharsets.UTF_8,
StandardOpenOption.APPEND)){
writer.write(“Hello World -字母哥!!”);
}
}
2. Files.write(Java7)
这种方式是实现文本文件简单读写最方便快捷的方式。
@Test
void testCreateFile2() throws IOException {
String fileName = “D:\data\test\newFile2.txt”;
// 从JDK1.7开始提供的方法
// 使用Files.write创建一个文件并写入
Files.write(Paths.get(fileName),
“Hello World -创建文件!!”.getBytes(StandardCharsets.UTF_8));
// 追加写模式
Files.write(
Paths.get(fileName),
“Hello World -字母哥!!”.getBytes(StandardCharsets.UTF_8),
StandardOpenOption.APPEND);
}
3. PrintWriter
PrintWriter是一个比较古老的文件创建及写入方式,从JDK1.5就已经存在了,比较有特点的是:PrintWriter的println方法,可以实现一行一行的写文件。
@Test
void testCreateFile3() throws IOException {
String fileName = “D:\data\test\newFile3.txt”;
// JSD 1.5开始就已经存在的方法
try (PrintWriter writer = new PrintWriter(fileName, “UTF-8”)) {
writer.println(“Hello World -创建文件!!”);
writer.println(“Hello World -字母哥!!”);
}
// Java 10进行了改进,支持使用StandardCharsets指定字符集
/*try (PrintWriter writer = new PrintWriter(fileName, StandardCharsets.UTF_8)) {
writer.println(“first line!”);
writer.println(“second line!”);
} */
}
4.File.createNewFile()
最后
由于细节内容实在太多了,为了不影响文章的观赏性,只截出了一部分知识点大致的介绍一下,每个小节点里面都有更细化的内容!
小编准备了一份Java进阶学习路线图(Xmind)以及来年金三银四必备的一份《Java面试必备指南》
大厂Java面试题解析+核心总结学习笔记+最新讲解视频+实战项目源码】](https://bbs.csdn.net/forums/4f45ff00ff254613a03fab5e56a57acb)收录**