美文网首页
IO流之copy文件

IO流之copy文件

作者: writeanewworld | 来源:发表于2018-11-07 18:40 被阅读0次
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文件

      本文链接:https://www.haomeiwen.com/subject/ksxbxqtx.html