0

我正在尝试开发一个可以读取文件的应用程序。但我不知道如何改变阅读器指针的位置,请帮忙?

for(int i=0; i<tab.length; i++){

    char cbuf[] = new char[tab[i]];

    try {
        InputStream ips=new FileInputStream(fichier); 
        InputStreamReader ipsr=new InputStreamReader(ips);
        BufferedReader br=new BufferedReader(ipsr);

                    //I need to change the position of the pointer here
        br.read(cbuf, 0, tab[i]);


        tabS[i] = new String(cbuf);
        System.out.println(tabS[i]);

        br.close();
    } catch (Exception e){
        System.out.println(e.toString());
    }
}
4

3 回答 3

1

读取命令可让您输入下一个字符。使用循环来接收字符

// reads and prints BufferedReader
     int Alength = 10;
     int array[] = new int [Alength];
     int value = 0;
     int index = 0;
     while((value = br.read()) != -1 && index < Alength)
     {
         array[index++] = value;
     }
于 2013-07-17T12:54:34.113 回答
0

请参阅跳过

br.skip(1000L);

不幸的是没有long tell()方法,所以我想知道它是否适合。

于 2013-07-17T13:21:25.890 回答
0

例如代码 -

int c = -1;
while((c=br.read())!=-1){
     //do whatever you like with ch
     char ch = (char)c;
     ...
     ...
}
于 2013-07-17T13:13:55.203 回答