前言 :首先IO兩字母得理解下,別面試官問(IO字母)的含義及全稱是什麼一臉懵。
I所謂的就是input.
O所謂就是Output.
1.File類的使用
2.IO流原理及流的分類
3.節點流(或文件流)
4.緩衝流
5.轉換流
6.標準輸入、輸出流
File類的使用:常用方法 一
File file3 =new File(pathname:“D:\io”);
System.out.println("輸出以下判斷文件是否存在 ")
常用方法 二
常用方法三
public class FileTest {
// 構造器一
@Test
public void test1() {
File file = new File("hello.txt");
System.out.println(file);
}
// 構造器二:
@Test
public void test2() {
File file2 = new File("hi.txt");
System.out.println(file2);
}
@Test //構造器三: 文件的創建
public void test3() throws IOException {
File file3 =new File("hi.txt");
if (!file3.exists()) {
file3.createNewFile();
System.out.print("創建成功");
//}else {
// System.out.println("刪除成功");
}
}
}
public class FileDemo {
@Test // 創建文件夾
public void test1() throws IOException {
File file = new File(“D:\io\hello.txt”);
File destfile =new File(file.getParent(),“haha.txt”);
boolean newfile=destfile.createNewFile();
if (newfile ) {
System.out.println(“創建成功!”);
}
}
}
【轉載註明出處,還望尊重原創 】