比较并匹配文本文件中的readLine()和文本 [英] Compare and match readLine() and text in a text file

查看:74
本文介绍了比较并匹配文本文件中的readLine()和文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本文件,我打开文件并尝试将文本文件的内容与文本匹配。这是我的代码:


FileInputStream input = new FileInputStream(" BinaryFp.txt");

BufferedReader br = new BufferedReader(new InputStreamReader(输入));

for(int i = 1; i< 801; i ++)

{

pdtNo = br.readLine();

if(pdtNo ==" M5250")

System.out.println(" true");

else

System.out.println(" false");

}

问题是,我不知道为什么答案总是错误的。应该有1场比赛。我可以用任何方式比较M5250吗?文本文件中有文本?

I have a text file, i open the file and try to match the contents of the text file to a text. Here''s my code:

FileInputStream input = new FileInputStream ("BinaryFp.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(input));
for(int i=1;i<801;i++)
{
pdtNo = br.readLine();
if(pdtNo=="M5250")
System.out.println("true");
else
System.out.println("false");
}
The problem is, i don''t know why the answer is always false. There should be 1 match. Is ther any way that i can compare "M5250" with text in the text file?

推荐答案


我有一个文本文件,我打开文件并尝试匹配文本文件的内容为文本。这是我的代码:


FileInputStream input = new FileInputStream(" BinaryFp.txt");

BufferedReader br = new BufferedReader(new InputStreamReader(输入));

for(int i = 1; i< 801; i ++)

{

pdtNo = br.readLine();

if(pdtNo ==" M5250")

System.out.println(" true");

else

System.out.println(" false");

}

问题是,我不知道为什么答案总是错误的。应该有1场比赛。我可以用任何方式比较M5250吗?文本文件中的文字?
I have a text file, i open the file and try to match the contents of the text file to a text. Here''s my code:

FileInputStream input = new FileInputStream ("BinaryFp.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(input));
for(int i=1;i<801;i++)
{
pdtNo = br.readLine();
if(pdtNo=="M5250")
System.out.println("true");
else
System.out.println("false");
}
The problem is, i don''t know why the answer is always false. There should be 1 match. Is ther any way that i can compare "M5250" with text in the text file?



始终使用str.equals(otherString)来比较字符串。不要使用==。

Always use str.equals(otherString) for comparing strings. Do not use == for that.



始终使用str.equals(otherString)来比较字符串。不要使用==。
Always use str.equals(otherString) for comparing strings. Do not use == for that.



我尝试使用str.equals(otherString),但它不起作用> _<

I tried using str.equals(otherString), but it doesn''t works >_<



我尝试使用str.equals(otherString),但它不起作用> _<
I tried using str.equals(otherString), but it doesn''t works >_<



发布你的试用方式。

Post how you have tried it.


这篇关于比较并匹配文本文件中的readLine()和文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆