A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 心弦上的景致 中级黑马   /  2013-4-9 15:23  /  1705 人查看  /  7 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

本帖最后由 心弦上的景致 于 2013-4-10 12:23 编辑

  1. import java.io.*;

  2. public class Inttt {

  3. public static void main(String[] args) {
  4.   String name1="F:\\我的文档\\123.jpg";
  5.   String name2="F:\\我的文档\\555.jpg";
  6.   try {
  7.    BufferedInputStream in = new BufferedInputStream(
  8.      new FileInputStream(name1));
  9.    BufferedOutputStream out = new BufferedOutputStream(
  10.      new FileOutputStream(name2));
  11.    int buffer = 8192;
  12.    byte[] bt = new byte[buffer];
  13.    int read;
  14.    if (in != null) {
  15.     while (true) {
  16.      if ((read = in.read(bt,0,bt.length)) != -1) {
  17.       out.write(bt,0,read);
  18.      }else{
  19.       break;
  20.      }
  21.     }
  22.    }
  23.    in.close();
  24.   } catch (Exception e) {

  25.   }

  26. }

  27. }
复制代码

评分

参与人数 1技术分 +1 收起 理由
陈丽莉 + 1

查看全部评分

7 个回复

倒序浏览
不能用中文做为目录名

评分

参与人数 1技术分 +1 收起 理由
陈丽莉 + 1

查看全部评分

回复 使用道具 举报
郭彦君 发表于 2013-4-9 15:26
不能用中文做为目录名

嗯 这个细节被我忽略了 ,但是编译报错误 不是中文目录导致的。
回复 使用道具 举报
我这可以运行啊,没问题啊,除了没有关闭输出流

评分

参与人数 1技术分 +1 收起 理由
陈丽莉 + 1

查看全部评分

回复 使用道具 举报
yufeng47 发表于 2013-4-9 15:36
我这可以运行啊,没问题啊,除了没有关闭输出流

这都被你发现了 好样的。
回复 使用道具 举报
你这个代码写的比较费解,尤其条件判断那块儿,为什么用 in!=nul来l判断,然后又用无限循环来判断。给你个简单的代码看看
  1. import java.io.*;

  2. public class Temp1 {

  3.         public static void main(String [] args){
  4.                 FileInputStream fis = null;
  5.                 FileOutputStream fos = null;
  6.                 try{
  7.                         fis = new FileInputStream("C:\\ks77.ini");
  8.                         fos = new FileOutputStream("C:\\1.txt");
  9.                         byte [] bt = new byte[1024];
  10.                         int num = 0;
  11.                         while((num = fis.read(bt))!=-1){                              
  12.                                 fos.write(bt);
  13.                         }
  14.                 }
  15.                 catch(IOException e){
  16.                         System.out.println(e.toString());
  17.                 }
  18.                 finally{
  19.                         if(fis==null)
  20.                                 try{
  21.                                         fis.close();
  22.                                 }
  23.                                 catch(IOException e){
  24.                                         System.out.println(e.toString());
  25.                                 }
  26.                         if(fos==null)
  27.                                 try{
  28.                                         fos.close();
  29.                                 }
  30.                                 catch(IOException e){
  31.                                         System.out.println(e.toString());
  32.                                 }        
  33.                 }
  34.         }
  35. }
复制代码

评分

参与人数 1技术分 +1 收起 理由
陈丽莉 + 1

查看全部评分

回复 使用道具 举报
我这编译没有问题~~话说楼主的代码看起来好费劲,所以都没看~~~~多按个Tab多好~~~~~~~
回复 使用道具 举报
若还有问题,继续追问; 没有的话,将帖子分类改成【已解决】哦~

点进自己的帖子,编辑->标题左侧有下拉菜单->改变分类->保存~
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马