IO流之copy文件

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();
        }
    }

}
}

你可能感兴趣的:(IO流之copy文件)