1,可能是BUFFER的原因!
2,两者的差别很大!DataInputStream有很多独有的方法能读取文件中的数据类型.
3,是的!

解决方案 »

  1.   

    buffer有什么原因?
    是不是BufferedInputStream读不了文件中的数据?比如象word,excel,gif等文件中的数据?
      

  2.   

    应该不会!你用什么方法读的!?如果都是用read()的话,那应该没什么问题的呀!因为该方法是在inputstream中定义的,在两者中的实现是一样的呀!根据我的判断要不问题出在缓冲上,要不就是程序有问题.后者的可能性大一点!(你为什么要用DataInputStream啊!?这一般是用在读DataOutputstream输出的文件的!)
      

  3.   

    java.io 
    Class BufferedInputStream
    java.lang.Object
      |
      +--java.io.InputStream
            |
            +--java.io.FilterInputStream
                  |
                  +--java.io.BufferedInputStream
    --------------------------------------------------------------------------------public class BufferedInputStream
    extends FilterInputStream
    A BufferedInputStream adds functionality to another input stream-namely, the ability to buffer the input and to support the  and reset methods. When the BufferedInputStream is created, an internal buffer array is created. As bytes from the stream are read or skipped, the internal buffer is refilled as necessary from the contained input stream, many bytes at a time. The  operation remembers a point in the input stream and the reset operation causes all the bytes read since the most recent  operation to be reread before new bytes are taken from the contained input stream. 
      

  4.   

    java.io 
    Class DataInputStream
    java.lang.Object
      |
      +--java.io.InputStream
            |
            +--java.io.FilterInputStream
                  |
                  +--java.io.DataInputStreamAll Implemented Interfaces: 
    DataInput --------------------------------------------------------------------------------public class DataInputStream
    extends FilterInputStream
    implements DataInput
    A data input stream lets an application read primitive Java data types from an underlying input stream in a machine-independent way. An application uses a data output stream to write data that can later be read by a data input stream. Data input streams and data output streams represent Unicode strings in a format that is a slight modification of UTF-8. (For more information, see X/Open Company Ltd., "File System Safe UCS Transformation Format (FSS_UTF)", X/Open Preliminary Specification, Document Number: P316. This information also appears in ISO/IEC 10646, Annex P.) Note that in the following tables, the most significant bit appears in the far left-hand column. All characters in the range '\u0001' to '\u007F' are represented by a single byte: 0 bits 6-0 The null character '\u0000' and characters in the range '\u0080' to '\u07FF' are represented by a pair of bytes: 1 1 0 bits 10-6 
    1 0 bits 5-0 
    Characters in the range '\u0800' to '\uFFFF' are represented by three bytes: 
    1 1 1 0 bits 15-12 
    1 0 bits 11-6 
    1 0 bits 5-0 The two differences between this format and the "standard" UTF-8 format are the following: The null byte '\u0000' is encoded in 2-byte format rather than 1-byte, so that the encoded strings never have embedded nulls. 
    Only the 1-byte, 2-byte, and 3-byte formats are used. 
      

  5.   

    就是因为使用BufferedInputStream不能读文件中的内容,所以只好使用DataInputStream。
    程序片断如下:
     public void uploadFile(javax.servlet.http.HttpServletRequest req) throws IOException,Exception {
         try {
            String contentType=req.getContentType();
            int contentLength=req.getContentLength();
            java.io.DataInputStream dis=new java.io.DataInputStream(req.getInputStream());
    //此句改成如下就只能读文本文件正常,其他文件读取就不正常。不知为何!      java.io.BufferedInputStream bis=new java.io.BufferedInputStream(req.getInputStream());
            int once = 0;
            int total = 0;
            byte[] buffer=new byte[contentLength];
            while ((total<contentLength) && (once>=0)) {
              once = dis.read(buffer,total,contentLength);
              total += once;
            }
            int boundaryStart=contentType.indexOf("boundary=");
            boundaryStart=boundaryStart+"boundary=".length();
            String boundary="--"+contentType.substring(boundaryStart);        int pos=getFormNameIndex(buffer,"filename=\"".getBytes(),1)+"filename=\"".length();
            int posEnd=getFormNameIndex(buffer,"\"".getBytes(),pos);
            String filename=new String(buffer,pos,posEnd-pos);
            pos=filename.lastIndexOf(".");
            String filenames=System.currentTimeMillis()/1000+filename.substring(pos);
            pos=getFormNameIndex(buffer,"Content-Type: ".getBytes(),1);
            pos=getFormNameIndex(buffer,"\r\n".getBytes(),pos+1);
            int endpos=getFormNameIndex(buffer,boundary.getBytes(),pos+20);
            int len=endpos-pos;
            System.out.println("get content:"+new String(buffer,pos,len));        //java.io.DataOutputStream bos= new java.io.DataOutputStream(new java.io.FileOutputStream(new java.io.File(filepath,filenames)));
            BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream(filename));
            bos.write(buffer,pos,len);        dis.close();
            bos.close();
         }catch(Exception exc) {
            throw new Exception("upload failed.");
         }finally{ }
      

  6.   

    Patrick_DK(疾风摩郎)
    不好意思,看不懂是何意思,能否给解释一下?谢谢!
      

  7.   

    意思基本是能看懂,但有些字符如
    1 1 0 bits 10-6 
    1 0 bits 5-0 
    等不知是何意思
      

  8.   

    DataInputSteam:可以读输入流基本类型的操作,比如readInt(),readDouble(),readLong()...
    BufferedInputStream是FileterInputStream子类,避免每次都物理得读取,告诉从缓冲区读,和FileInputSteam等InputStream子类联合使用(非FileterInputStream).
      

  9.   

    读的是excel文件时再写入某个目录时文件不能打开