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 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果