在我的文本文件-Java中获取数据 [英] Get Datas in My text file -Java
问题描述
你好,有人可以帮助我!
我堆叠这个问题..我只想要查看 员工数据 大>。数据保存在我的记事本中,这是我的记事本中的内容。
Hi can someone help me !
I am stack with this problem.. All I want is that I want to view Employees Data. The Data was save in my Notepad and this is what is in my Notepad.
<br />
#Employee.txt
Employee:{Fullname="User", JobTitle="Guard", Age="31"}
Employee:{Fullname="SecondUser", JobTitle="Janitor", Age="32"}
Employee:{Fullname="Johnson", JobTitle="SysAd", Age="33"}
我可以显示所有t通过使用以下代码,数据在我的 Employee.txt 中:...
I can show all the data''s in my Employee.txt by having this code: ...
import java.io.*;
import java.util.*;
public class ReadEmployees {
public static void main(String[] args) throws IOException {
Scanner scan = new Scanner(System.in);
BufferedReader readfile = null;
File filename = new File("Employee.txt");
try {
readfile = new BufferedReader(new FileReader(filename));
String line = readfile.readLine();
do{
line = readfile.readLine();
if (line != null) {
String input = line;
String str = input.replaceAll("Employee:+|,+|}+|\\{+|\\''", "");
String finalstr = str.replaceAll("\\s","\n");
String[]parts = finalstr.split("\\=+|\n");
System.out.println(finalstr+"\n");
}
}while(line!=null);
readfile.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
这是程序的输出:打击>
this is the output of the program:
run:
Fullname="User"
JobTitle="Guard"
Age="31"
Fullname="SecondUser"
JobTitle="Janitor"
Age="32"
Fullname="Johnson"
JobTitle="SysAd"
Age="33"
BUILD SUCCESSFUL (total time: 0 seconds)
>但我希望在我运行程序时它会要求输入 FullName 然后如果输入 FullName 它将在我的 Employee.txt 如果发现它将显示员工的数据。
我想要输出:
> But I want that when I run the program It will ask to enter a FullName then If a FullName is entered It will search in my Employee.txt and if found it will display the Data''s of the Employee.
I want to have this output:
run:
enter Fullname: User
"User"
//then it will search for the name and if found it will be displayed
Fullname="User"
JobTitle="Guard"
Age="31"
BUILD SUCCESSFUL (total time: 0 seconds)
I am hoping and waiting for an answer.
Thank You..
: - (
推荐答案
if(str.contains("User"){
System.out.println(finalstr+"\n");
}
这篇关于在我的文本文件-Java中获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!