如标题所以,我用FileInputStream读取一个纯文本文件,然后想再用一个流将其写入到我写的(byte buffer[] = new byte[1024])buffer中,请问用什么流可以?

解决方案 »

  1.   

    文本文件不要用FileInputStream用FileReader更好,读成String再转码也成。
      

  2.   

    给点代码呗。其实我想用的是读取到一个流中,然后将其转换成String
      

  3.   

    public class Test {
    public static void ReadData() {
    try {
    FileReader read = new FileReader("E:/*.txt");
    BufferedReader br = new BufferedReader(read);
    String row;
    int index = 0;
    int i = 0;
    String cardId = "";
    String passwd = "";
    while ((row = br.readLine()) != null) {
    index++;
    if (index % 2 == 0) {
    StringTokenizer t = new StringTokenizer(row, "|*|");// "|*|"为分隔符 
    cardId = t.nextToken();//将第一个记录赋给变量cardId 
    passwd = t.nextToken();//将第二个记录赋给变量passwd 
    System.out.println("cardId:" + cardId + "      passwd:"
    + passwd);
    }
    }
    } catch (FileNotFoundException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    }
    } public static void main(String[] args) throws Exception {
    ReadData();
    }
    }
    /******************************/
    *.txt内容:aaa|*|bbbaaa|*|bbbaaa|*|bbbaaa|*|bbb
    /******************************/