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条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!