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

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog