正确的做法应该是先把内容读到一个以String为基础的StringReader中去,再用indexOf在String中查找后,再把String通过getBytes方法转为byte[] 数组。

解决方案 »

  1.   

    如果文件不大的话
    import java.io.*;
    import java.util.*;public class WriteFile{
        public static void main(String[] args) 
        {
         byte buffer[]=new byte[4096];
            try{
                FileInputStream fileIn = new FileInputStream("default.xml");
                int bytes = fileIn.read(buffer,0,4096);
                try{
                    String str = new String(buffer,0,bytes);
                    System.out.println(str);
                }catch(Exception e){
                }
                fileIn.close();
            }catch(Exception e){
            } 
        } 
    }
      

  2.   

    看看C/C++的算法吧,是不是2进制都一样的,C里面都是char,才不管是不是ASCII码呢。
      

  3.   

    String str = new String(byteArray);  //byteArray is ur byte[]
    int index = str.indexOf(stringToFind);