首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

大附件上载java.io.IOException: 拒绝访问

2013-03-01 
大附件下载java.io.IOException: 拒绝访问。写在Servlet服务器的代码System.out.println(开始下载)//Inp

大附件下载java.io.IOException: 拒绝访问。
写在Servlet服务器的代码   
System.out.println("开始下载");
//    InputStream stream=request.getInputStream(); //锟斤拷取锟酵伙拷锟剿达拷锟酵癸拷4锟斤拷锟斤拷
//    String string=getReadToString(stream);
    System.out.println("stream="+string);
    JSONObject json=JSONObject.fromObject(string);
    InputStreamReader inputStreamReader =null;
    RandomAccessFile random = null;
    FileChannel channel = null;
    byte[] bytes=null;
    BufferedOutputStream outStream = null;
    ServletOutputStream sos = null;
    try {
//参数设值
        int startsSize=json.getInt("startPosition");
        int outSize=json.getInt("endPosition");
        String filepath=json.getString("downFileDir");

        StringBuffer buffer=null;

        random = new RandomAccessFile(filepath,"r");
        channel = random.getChannel();
        long fileSize = random.length();    //锟侥硷拷锟斤拷小
        //response.setContentType("application/pdf");
        filepath = new String(filepath.getBytes("gb2312"), "ISO8859-1");
    //设返回文件大小
           response.setContentLength((int) fileSize);
          bytes= new byte[(int)(outSize-startsSize)];
          MappedByteBuffer out =channel.map(MapMode.READ_ONLY,(startsSize),(outSize));
          out.get(bytes);     
          clean(out);//清空MappedByteBuffer句柄
          System.out.println(out+"out");
//向客户端输出流
          outStream = new BufferedOutputStream(response.getOutputStream());
          outStream.write(bytes,0,bytes.length);
          outStream.flush();
          outStream.close();
       writeJson(response, new String(bytes));    
      } catch (Exception e) {
        e.printStackTrace();
      } finally {
        try {
          if( channel != null){
            channel.close();
          }
          if (random != null) {
              random.close();
          }
          if (inputStreamReader != null) {


            inputStreamReader.close();
          }
          if(  outStream != null )  outStream.close();
          
          if(sos != null)sos.close();
          
        } catch (Exception e) {
          e.printStackTrace();
        }
    } 
io; MappedByteBuffer; 文件下载; FileChannel?;流的输入输出
[解决办法]
应该不是权限问题,权限问题的话
 random = new RandomAccessFile(filepath,"r");
这句就该报错了
试了下
MappedByteBuffer out =channel.map(MapMode.READ_ONLY,(startsSize),(outSize));
如果startsSize + outSize >  fileSize了
倒是会报拒绝访问,你可以检查下这3个参数看

热点排行