IO流之copy文件
2018-11-07 本文已影响0人
writeanewworld
public class TestMain {
public static void main(String[] args) {
String filePathA = "C:/Users/user/Desktop/A.txt";
String filePathB = "C:/Users/user/Desktop/B.txt";
InputStream aio = null;
OutputStream bio = null;
try {
aio = new FileInputStream(filePathA);
if (aio.available() != 0) {
byte[] buffer = new byte[1024];
while (aio.read() != -1) {
aio.read(buffer);
}
bio = new FileOutputStream(filePathB);
bio.write(buffer);
}
} catch (Exception e) {
e.printStackTrace();
}finally {
try {
bio.close();
aio.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}