记住使用flush()函数
在进行IO中的输出流的时候,有时会遇到输出的文件中没有被写入内容,这时可能是由于没使用flush()函数
故,可以这样写:
public class demo1 {
public static void main(String[] args) {
File fileOutput = new File("D:\\workspaceIDEA\\demo1\\src\\com\\stream\\aa.txt");
String inputPath = "D:\\workspaceIDEA\\demo1\\src\\com\\stream\\ss.txt";
try {
if (!fileOutput.exists()){
fileOutput.createNewFile();
}
BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(inputPath));
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(fileOutput));
int len;
byte[] bytes = new byte[1024];
while ((len=bufferedInputStream.read(bytes))!=-1){
bufferedOutputStream.write(bytes,0,len);
//调用flush函数
bufferedOutputStream.flush();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}