FileInputStream is a stream to grab the information from files.Combined with FileOutputStream, we can achieve the function of copying.
Examples:
public class Demo4 {
public static void main(String[] args) {
String content = null;
byte[] buffer = new byte[1024];
int size = 0;
File file = new File("C:/Users/caich5/Desktop/aaaa.txt");
InputStream input = null;
try {
input = new FileInputStream(file);
OutputStream output = new FileOutputStream("C:/Users/caich5/Desktop/tttd.txt");
while((size = input.read(buffer))!= -1){
//show in console
content = new String(buffer,0,size);
System.out.println(content);
//copy to another file
output.write(buffer, 0, size);
}
input.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Tips: FileInputStream,FileOutputStream,both of them are low lever stream.