IO stream realizes the copying of articles

Io flow realizes article replication

1 byte input stream: FileInputStream
output stream FileOutputStream
2 universal copy tool
FileInputStream fis = new FilrInputStream("source file path");
FileOutputStream fos = new FilrOutputStream("target file path");
efficient copy
byte[] buf = new byte [8192];
int len ​​= 0;
while((len=fis.read(buf))!=-1){ fos.write(buf,0,len); } fis.close(); fos.close() ;



FileInputStream fis = new FilrInputStream("源文件路径");
FileOutputStream fos = new FilrOutputStream("目标文件路径");
高效复制
byte[] buf = new byte[8192];
int len = 0;
while((len=fis.read(buf))!=-1){
    
    
fos.write(buf,0,len);
}
fis.close();
fos.close();

Character stream reading stream FileReader
writing stream FileWriter
usage scenario: processing plain text data
The bottom layer of the character stream is also implemented internally by byte stream, we don’t need to pay attention to the encoding of text data when using
BufferedReader comes with 8kb buffer
BufferedWriter
character stream Copy of

1创建读取源文件的缓冲字符流
BufferedReader br = new BufferedReader(new FileReader("源文件的地址"))
2创建一个写出文件的缓冲字符流
BufferedWriter bw = new BufferedWriter(new FileWriter("目标文件的路径"))
3高效复制
String line = null;
while((line=bw.readLine())!=null){
    
    //判断是否已经读取到文件的末尾
bw.write(line);
bw.newLine();
}
br.close();
bw.close();

IO stream summary
Read in and write out
Character stream for reading text.
Copy operation directly use byte stream
IO extension function.
Read property file through IO, xxx.properties
Properties pro = new Properties();
pro.load(byte stream/character The stream is read into the property file)
String value=pro.getProperty(key)

Guess you like

Origin blog.csdn.net/HelloWorld1995/article/details/114240778