import java.io.FileReader;
public class TestFile {
public static void main(String[] args) {
try{
int i = 0;
String str = "";
FileReader fr = new FileReader("f://aaa.txt");
char[] ch = new char[1024];
while(fr.read(ch, 0, 1024) != -1){
str += new String(ch);
ch = new char[1024];
}
str += new String(ch);
while((i = str.lastIndexOf("我")) != -1){
System.out.println("我位于---" + i);
str = str.substring(0, i);
}
}catch(Exception e){
e.printStackTrace();
}
}
}
本文介绍了一个Java程序示例,该程序演示了如何使用FileReader类从指定路径读取文本文件,并通过循环遍历查找特定字符的位置。此外,还展示了如何截断已找到特定字符之后的字符串。
700

被折叠的 条评论
为什么被折叠?



