this is x.txt
file
12=aa
1234=ytuu
157=lkjh
// above is the sample of data(from 7700 similiar lines in actual file) in a txt file . i want to use that data for condition checking in my java code like
if (n==12){
System.out.println("aa");}
else
if (n==1234){
System.out.println("ytuu");}
有什么方法可以访问这些数据,而不是在我的代码中键入所有行。
我是一个初学者,所以请帮助我。
最佳答案
如果您尝试读取属性文件,则应这样做
Properties properties = new Properties();
FileReader reader = new FileReader(new File("your_file.txt"));
properties.load(reader);
reader.close();
System.out.print(properties.getProperty("12"));
假设您的文件只是这种键=值对。
关于java - 如何将txt或pdf文件中的数据访问到Java代码中以进行条件检查,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33545141/