偶也要,谢谢!
[email protected]

解决方案 »

  1.   

    wo ye yao,[email protected]
      

  2.   

    比较乱,刚添加的注释,随便写的,自己参考一下String filename="",filename2="",flag="0";
    String tempname="11.111";
    //建立临时文件,把用户上传的所有信息全部放入该文件中
    File f1=new File("c:/",tempname);
    FileOutputStream o=new FileOutputStream(f1);
    InputStream in=request.getInputStream();
    byte b[]=new byte[10000];
    int n;
      while((n=in.read(b))!=-1)
      {
        o.write(b,0,n);  
       }
       o.close();
       in.close();
    //读临时文件,从中获取上传文件的名字和内容
    RandomAccessFile random=new RandomAccessFile(f1,"r");
    //读临时文件第二行,取上传文件的名字
    int second=1;
    String secondLine=null;
    while(second<=2)
    {
      secondLine=random.readLine();
      second++;
    }
    int position=secondLine.lastIndexOf("\\");
    //int position2=secondLine.indexOf("filename=");
    //String fileurl=getStr(secondLine.substring(position2+10,position));
    filename=getStr(secondLine.substring(position+1,secondLine.length()-1));
    filename2=secondLine.substring(position+1,secondLine.length()-1);
    random.seek(0);
    long forthEndPosition=0;
    int forth=1;
    //读文件内容
    while((n=random.readByte())!=-1 && (forth<=4))
    {
      if(n=='\n')
      {
        forthEndPosition=random.getFilePointer();
    forth++;
      }
    }//根据用户上传文件的名字,将该文件存入磁盘
    File f2=new File("D:/soft/",filename);
    session.setAttribute("Name",filename);
    RandomAccessFile random2=new RandomAccessFile(f2,"rw");
    random.seek(random.length());
    long endPosition=random.getFilePointer();
    long =endPosition;
    int j=1;
    //文件的内容是在临时文件的第四行结束的位置到倒数第六行结束的位置
    while((>=0) && (j<=6))
    {
      --;
      random.seek();
      n=random.readByte();
      if(n=='\n')
      {
        endPosition=random.getFilePointer();
    j++;
      }
    }
    random.seek(forthEndPosition);
    long startPoint=random.getFilePointer();while(startPoint<endPosition-1)
    {
      n=random.readByte();
      random2.write(n);
      startPoint=random.getFilePointer();
    }
    f1.delete();
    flag="1";
      

  3.   

    daxuanfeng(好天) 
    [email protected]
    我也要谢谢
      

  4.   

    daxuanfeng(好天) 
    我也要啊,谢谢
    [email protected]