【发布时间】:2016-08-15 20:34:53
【问题描述】:
例如,我在文本文件中有 2 行数据: 你好!早晨 你好!晚上
我只想要一行的最后一个字。我使用了这段代码,但不是显示 Evening,而是显示 Hi!晚上 searchName 是嗨!
try{
BufferedReader in = new BufferedReader(fr);
try {
while((s=in.readLine())!=null){
countline++;
String[] words=s.split(" ");
for(String word:words){
if(word.contains(searchName)){
System.out.println(words);
int lastSpace=word.lastIndexOf(" ");
String addres=word.substring(lastSpace+1,word.length());
System.out.println(addres);
}
}
}
in.close();
} catch (IOException e) {
System.out.println("No address found for your name..We are updating");
}
}finally {
}
【问题讨论】: