Advertisement

在JAVA中使用字节流时一次读取数组

阅读量:
复制代码
    ```

java
    package cn.itcast;
    
    import java.io.*;
    
    public class ISCopyFile2 {
    public static void main(String[] args) 
    throws IOException {
        // 建立输入流对象,实现文件连接
        InputStream is = new FileInputStream("lib/苏苏.JPG");
        // 构建输出流对象,完成文件连接
        OutputStream os = new FileOutputStream("lib/小苏.JPG");
        // 声明变量
        byte [] bytes = new byte[2048]; // 由于需要读取字节数组,
        因此设定一个
        // 数组变量,单位可自由选择,但推荐使用1024的整数倍
        int len ;
        // 进入循环操作
        while ((len = is.read(bytes))!=-1 ){
            // 执行复制操作
            os.write(bytes

全部评论 (0)

还没有任何评论哟~