st=buff.read();
-->
st=buff.readLine();

解决方案 »

  1.   

    BufferedInputStream 中的read()没用和InputStream一样返回下一个Byte你用String当然不行了
    不用循环吧,如果是,System.out.println(st);不在循环内部,还不是一个输出
    boolean set=buff.canread();不对
    canRead() - Method in class java.io.File ,,另外大写canRead
      

  2.   

    多谢两位的指点,但是还是不清楚,这样吧,我把程序重写了一遍,依照两位的意见改了一下,但是还有点错误,请指正:
    import java.io.*;
    public class Xyuan{
    public static void main(String args[]) throws IOException {

    FileInputStream file=new FileInputStream("e:\\xy.txt");
    BufferedInputStream buff=new BufferedInputStream(file);
    String st;
    while(true){
     st=buff.read();
     }
     buff.close();
        int i=st.indexOf("xcv");
    int b=st.indexOf('v');
    String a=st.substring(i,b+1);
    System.out.println(a);

    错误在与st=buff.read();我不明白这是为什么????????
    }
      

  3.   

    C:\Program Files\Xinox Software\JCreator Pro\MyProjects\Xyuan\Xyuan.java:9: incompatible types
    found   : int
    required: java.lang.String
     st=buff.read();
                                         ^
    1 error这就是这个程序的错误!!!请指正,谢谢!!!
      

  4.   

    import java.io.*;
    public class Xyuan{
    public static void main(String args[]) throws IOException {
               DataInputStream ss=new DataInputStream(
                                          new BufferedInputStream(
                                              new FileInputStream("c:\\xy.txt") ));
    //FileInputStream file=new FileInputStream("e:\\xy.txt");
    //BufferedInputStream buff=new BufferedInputStream(file);
    char t=(char)ss.readByte();
                         char [] sb=new char[ss.available()];
                         int i=0;
     while(ss.available() != 0){
     sb[i++]=t;
                          t=(char)ss.readByte();
     }
                          String st=new String(sb);
     
                                         
           i=st.indexOf("xcv");
    int b=st.indexOf('v');
    String a=st.substring(i,b+1);
    System.out.println(a);
    } }
      

  5.   

    String st;
    while(true){
    st=buff.read();
    }
    --------->
    read()讀出來的是int型
    而st是String,當然不匹配了