区块链技术博客
www.b2bchain.cn

标题: The method write(int) in the type FileOutputStream is not applicable f …

b2bchain.cn区块链技术社区提供第9187篇技术文章标题: The method write(int) in the type FileOutputStream is not applicable f …
问题解答:

The method write(int) in the type FileOutputStream is not applicable for the arg

package Sample;

import
import
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class CopyGFile {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        String infile = "c:\copy.sql";
        String outfile = "c:\copy.txt";
        //获取源文件和目标文件的输出流
        FileInputStream fin = new FileInputStream(infile);
        FileOutputStream fout = new FileOutputStream(outfile);
        //获取输入输出通道
        FileChannel fcin = fin.getChannel();
        FileChannel fcout = fout.getChannel();
        //创建缓冲区
        ByteBuffer buffer = ByteBuffer.allocate(1024);
        while(true) {
            //clear方法重设缓冲区,使它可以接受读入的数据
            buffer.clear();
            //从输入通道中将数据读到缓冲区
            int r = fcin.read(buffer);
            //read方法返回读取的字节,可能为零,如果该通道已到达流的末尾,则返回-1
            if(r == -1) {
                break;
            }
            //flip方法让缓冲区可以将新读入的数据写入另一个通道
            buffer.flip();
            //从输出通道中将数据写入缓冲区
            fout.write(buffer);
        }
    }

}

标题: The method write(int) in the type FileOutputStream is not applicable f … 由www.b2bchain.cn 提供
文章整理自网络,只为个人学习与分享使用
链接地址https://www.b2bchain.cn/?p=9187

赞(0) 打赏
部分文章转自网络,侵权联系删除b2bchain区块链学习技术社区 » 标题: The method write(int) in the type FileOutputStream is not applicable f …
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

b2b链

联系我们联系我们