import java.io.*; public class FileStreamTest { public static void main(String[] args) { File file = new File("D:\\AppData\\Roaming\\IMG_8688.PNG"); FileInputStream inputStream = null; FileOutputStream fileOutputStream = null; try { inputStream = new FileInputStream(file); fileOutputStream = new FileOutputStream(new File("D:\\123.PNG")); byte[] bytes = new byte[10240]; int len; while((len = inputStream.read(bytes)) != -1) { fileOutputStream.write(bytes,0,len); } } catch (IOException e) { throw new RuntimeException(e); } finally { try { if(fileOutputStream != null) { fileOutputStream.close(); } if(inputStream != null) { inputStream.close(); } } catch (IOException e) { throw new RuntimeException(e); } } } }
import java.io.*;
public class FileStreamTest
{
public static void main(String[] args)
{
File file = new File("D:\\AppData\\Roaming\\IMG_8688.PNG");
FileInputStream inputStream = null;
FileOutputStream fileOutputStream = null;
try
{
inputStream = new FileInputStream(file);
fileOutputStream = new FileOutputStream(new File("D:\\123.PNG"));
byte[] bytes = new byte[10240];
int len;
while((len = inputStream.read(bytes)) != -1)
{
fileOutputStream.write(bytes,0,len);
}
}
catch (IOException e)
{
throw new RuntimeException(e);
}
finally
{
try
{
if(fileOutputStream != null)
{
fileOutputStream.close();
}
if(inputStream != null)
{
inputStream.close();
}
}
catch (IOException e)
{
throw new RuntimeException(e);
}
}
}
}
JAVA使用IO流的字节流实现复制文件-----JAVA
于 2023-07-07 21:25:18 首次发布