java - 将字符串与文件中的另一个字符串进行比较
问题描述
我已经尝试了“.equals”、“.contains”和“==”我仍然没有得到结果
String pre = "0917";
File file = new File("F:\\Eclipse\\Loading De Luna\\bin\\GlobePrefix.txt");
BufferedReader br = new BufferedReader(new FileReader(file));
String prefix;
while ((prefix = br.readLine()) != null)
if(prefix.equals(pre))
System.out.println("Found");
else System.out.println("Not Found");
.txt 文件包含以下字符串:
0817
0905
0906
0915
0916
0917
0926
0927
0935
0936
0937
0945
0955
0956
0965
解决方案
if (prefix.trim().equals(pre))
System.out.println("Found");
else
System.out.println("Not Found");
会解决问题。
推荐阅读
- javascript - jquery fileupload 不允许选择具有不同扩展名的文件
- python - 如何在异步服务器中实现超时?
- java - 如何在 .jsp 文件中呈现 HTML
- macos - 在 Karabiner 中,我可以从包含所有修饰符的超键映射到修改后的键吗?
- python - 键入命令“pydoc tensorflow”时如何避免“分段错误(核心转储)”?
- android - 改造调用提供默认值而不是所需的值
- java - 管理 JAR 中的依赖关系 - 测试自动化
- mysql - 从导入表中移动数据
- c# - VS2017 使用“打开文件夹”后无法加载文件或程序集 System.Runtime
- c# - DotNet Core C# 并发实体框架(重复键值唯一约束)