遇到一个缓冲流问题

末路--007 2019-09-15 09:29:02
写一个测试缓冲流,然后eclipse不让我添加文件的路径。 全代码: package itdsj; import java.io.BufferedOutputStream; import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; /**加入了字节缓冲流: * * 文件(任何文件)输入输出流:文件处于电脑上,java要通过操作 * 系统访问它。所以要每次用完都必须释放资源 * 1.创建源 * 2.选择流 * 3.操作 * 4.释放资源 * @author Mr xing * */ public class BufferedInputStream { public static void main(String[] args) { copyAllFile("D:/develop/workspace/Test/abc.txt","b.xtx"); } public static void copyAllFile(String srcFile,String destFile) { File src = new File(srcFile); File dest = new File(destFile); InputStream is = null; OutputStream os = null; BufferedInputStream bis = null; BufferedOutputStream bos = null; try { is = new FileInputStream(src); bis = new BufferedInputStream(is); os = new FileOutputStream(dest); bos = new BufferedOutputStream(os); byte[] lunch = new byte[1024]; int len = -1; while((len=bis.read(lunch))!=-1) { os.write(lunch,0,len); os.flush();//刷新 } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { if(null!=is) { try { is.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if(null!=os) { try { os.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if(null!=bis) { try { bis.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if(null!=bos) { try { bos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } } 它始终不让我添加这句话里的is. bis = new BufferedInputStream(is); 谁可以帮忙看看吗?
...全文
39 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

51,412

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧