lkext 2015-06-23 14:28 采纳率: 50%
浏览 1597
已采纳

jsp 用 RandomAccessFile上传文件

      File a=new File("D:/ceshi/2/2.txt");
        FileOutputStream a1=new FileOutputStream(a);
        InputStream b1=request.getInputStream();
        byte v[]=new byte[20000];
        int n;
        while((n=b1.read(v))!=-1)
        a1.write(v, 0, n);
        a1.close();
        b1.close();
        String filename="t.txt";
        byte cc[]=filename.getBytes("ISO-8859-1");
        filename=new String(cc);
           File c1=new File("D:/ceshi/2/"+filename);
           RandomAccessFile randomwrite=new RandomAccessFile(c1,"rw");
        RandomAccessFile randomread=new RandomAccessFile(a,"r");
        int second=1;
        String secondLine=null;
        while(second<=2)
        {
        secondLine=randomread.readLine();
        second++;
        }

        randomread.seek(0);
        long four=0;
        int four1=1;
        while((n=randomread.readByte())!=-1&&(four1<=4))
        {
        if(n=='\n')
        {
        four=randomread.getFilePointer();
        four1++;
        }
        }
    randomread.seek(randomread.length());
    long end=randomread.getFilePointer();

    int j=1;
    while( (end>=0) && (j<6))  
        {
              end--;
    randomread.seek(end);
     n=randomread.readByte();

        if(n=='\n')
        {
        end=randomread.getFilePointer();
        j++;
        }
        randomread.seek(four);
        while(four<end-1)
        {
        n=randomread.readByte();
        randomwrite.write(n);
        four=randomread.getFilePointer();
        }
        randomread.close();
        randomwrite.close();



        }

每次传完 文件后面都有一行多余的代码

  • 写回答

2条回答 默认 最新

  • devmiao 2015-06-23 15:15
    关注

    用fiddler调试下,看看提交的请求是不是有问题。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效