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

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© olkldksl 黑马帝   /  2011-11-7 19:54  /  1405 人查看  /  8 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

使用FileInputStream读取一个jpeg格式的图片
抛异常说找不到文件
但是可以找到txt,bmp格式的文件,这是为什么

8 个回复

正序浏览
olkldksl 黑马帝 2011-11-8 14:14:07
9#
有那个文件,算了,我传bmp格式的好了,不搞jpeg的了
回复 使用道具 举报
郭敏 黑马帝 2011-11-7 22:42:39
8#
{:soso_e101:} 嘿嘿,我弄错了,  我这运行正常啊?       FileInputStream fis = new FileInputStream("c:\\1.bmp"); 这句代码中的字符串是否更改成为 c:\\1.jpeg? 在你的C盘下是否存在jpeg格式的图片?
回复 使用道具 举报
olkldksl 黑马帝 2011-11-7 22:39:46
7#
- -!又不是缓冲流,flush什么呀,问题不在那,读取bmp格式的图片也可以,就是找不到jpeg格式的
回复 使用道具 举报
- -!又不是缓冲流,flush什么呀,问题不在那,读取bmp格式的图片也可以,就是找不到jpeg格式的
回复 使用道具 举报
兄弟: 在用到outputStream 流写数据里,千万记着在调用Write方法之后,加上flush() 刷新缓冲区,
你的程序问问题就出在这,你试试!
回复 使用道具 举报
public class PicClient {

        public static void main(String[] args) throws Exception {
//               
               
                Socket s = new Socket("192.168.1.126",10001);
                FileInputStream fis = new FileInputStream("c:\\1.bmp");
               
                OutputStream fos =  s.getOutputStream();
                int len = 0;
                byte[] buf = new byte[1024];
               
                while((len = fis.read(buf))!=-1){
                        fos.write(buf,0,len);
                }
                s.shutdownOutput();
               
                InputStream in = s.getInputStream();
                byte[] bufIn = new byte[1024];
                int num = in.read(bufIn);
                System.out.println(new String(bufIn,0,num));
               
                fis.close();
                s.close();
        }

}



public class PicServer {

        public static void main(String[] args) throws Exception {
                ServerSocket ss = new ServerSocket(10001);
               
                while(true){
                        Socket s = ss.accept();
                        new Thread(new ServerThread(s)).start();
                }
               
                //ss.close();
        }

}



public class ServerThread implements Runnable{
        private Socket s ;
        ServerThread(Socket s){
                this.s = s;
        }
        @Override
        public void run() {
                // TODO Auto-generated method stub
               
               
                try {
                       
                        FileOutputStream os = new FileOutputStream("1.jpg");
                        InputStream in = s.getInputStream();
               
                    int len = 0;
                    byte[] buf = new byte[1024];
               
                    while((len = in.read(buf))!=-1){
                            os.write(buf,0,len);
                    }
               
                    OutputStream outPut = s.getOutputStream();
                    outPut.write("上传成功".getBytes());
               
                    os.close();
                    s.close();
                       
                       
                } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
               
               
        }
       
       
}
回复 使用道具 举报
兄弟,把你的代码贴上来瞧瞧~~
回复 使用道具 举报
路径写对了吗??文件名大小写注意了吗?
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马