如何按顺序读取文件?
public static void main(String[] args){
String fichier ="E:\\fichiers\\test.txt";
int tab[] = {2, 2, 20, 8, 20, 8, 4, 3, 7, 3, 3, 3, 18, 139};
String tabS[] = new String[14];
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);
br.read(cbuf, 0, tab[i]);
tabS[i] = new String(cbuf);
System.out.println(tabS[i]);
} catch (Exception e){
System.out.println(e.toString());
}
}
}
我的文件内容只有这一行:
BOUUUUUUUUUUUUUUUUUUUUUU!
当我运行readMe方法时,我得到了这个:
BO BO BOUUUUUUUUUUUUUUUUUU BOUUUUUU BOUUUUUUUUUUUUUUUUUU BOUUUUUU BOUU BOU BOUUUUU BOU BOU BOU BOUUUUUUUUUUUUUUUU BOUUUUUUUUUUUUUUUUUUUUUU!
这里的问题是,每次他开始读取文件时,它都会从位置 0 开始。
请问有什么帮助吗?