我正在尝试开发一个可以读取文件的应用程序。但我不知道如何更改读卡器指针的位置,请帮忙吗?
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());
}
}
答案 0 :(得分:1)
使用read命令可以接收下一个字符。使用循环来接收字符
// 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;
}
答案 1 :(得分:0)
E.g。代码 -
int c = -1;
while((c=br.read())!=-1){
//do whatever you like with ch
char ch = (char)c;
...
...
}
答案 2 :(得分:0)