我创建了一个方法,BufferedReader
该方法可以打开程序先前创建的文本文件并提取一些字符。我的问题是它提取了整行,我只想在指定字符之后提取:
.
这是我的try/catch
块:
try {
InputStream ips = new FileInputStream("file.txt");
InputStreamReader ipsr = new InputStreamReader(ips);
BufferedReader br1 = new BufferedReader(ipsr);
String ligne;
while((ligne = br1.readLine()) != null) {
if(ligne.startsWith("Identifiant: ")) {
System.out.println(ligne);
id = ligne;
}
if(ligne.startsWith("Pass: ")) {
System.out.println(ligne);
pass = ligne;
}
}
System.out.println(ligne);
System.out.println(id);
System.out.println(pass);
br1.close();
} catch (Exception ex) {
System.err.println("Error. "+ex.getMessage());
}
此刻,我String
将整个 id 返回到我的 id 中ligne
,对于pass
- 顺便说一下,所有这些sysout
都是测试,在那里毫无用处。
如果有人知道如何将 id 之后的行:
而不是整行发送到 id,我可能搜索不好,但 google 不是我的朋友。