I/O流
序列化和反序列化:将对象转为字节串称为序列化;将字节转为对象称为反序列化;
import java.io.*;
public class IO {
public IO(String pathRead,String pathWrite ) throws IOException {
File f = new File(pathRead);
File r = new File(pathWrite);
if (!f.exists()){return;}
if (r.exists()){r.delete();r.createNewFile();};
FileOutputStream fp = new FileOutputStream(r);
OutputStreamWriter sw= new OutputStreamWriter(fp,"utf-8");
BufferedReader sb= new BufferedReader(new InputStreamReader(new FileInputStream(f),"utf-8"));
String string;
while((string = sb.readLine())!=null) {
sw.append(string);
sw.append("\r\n");
}
sw.close();
}
public static void main(String[] args) throws IOException {
String str="C:\\Users\\86187\\Desktop";
File book =new File("C:\\Users\\86187\\Desktop");
//book.mkdir();创建一个文件夹
File[] files=book.listFiles();
if (book.isFile()){
System.out.println("是文件");
}else
if(book.isDirectory()){
for(int i=0;i<files.length;i++){
System.out.println(files[i].getName());
//获取文件名字
// str.toLowerCase().endsWith(".txt");判断文件夹的格式
}
}
{};
IO my= new IO("C:\\Users\\86187\\Desktop\\test.txt","C:\\Users\\86187\\Desktop\\1.txt");
}
}