java字符串连接不相等_java – 两个相同的字符串不相等(不是指针/引用错误)

我从文件中读取一行:

KatalogObrazków132

意味着我应该寻找以下数据:

C:\Users\NAME_OF_THE_USER/KatalogObrazków

所以我这样做,但有可怕的事情发生.在splitLine [0]中,我有一个单词“KatalogObrazków”但是计算机说“KatalogObrazków”.equals(splitLine [0])是假的,分裂线后没有左边的splitLine [0]空格.请看下面的代码.

BufferedReader br = new BufferedReader(new FileReader(path));

String line;

String[] splitLine;

if ((line = br.readLine()) != null) {

splitLine = line.split(" ");

System.out.println(splitLine[0]);//1st line of output

System.out.println("KatalogObrazków".equals(splitLine[0]));//these are not EQUAL!!!!!??? WHY?

imageDirectoryPath = System.getProperty("user.home")+"/" + splitLine[0];

System.out.println(new File(imageDirectoryPath).exists());

delay = Integer.parseInt(splitLine[1]);

fontSize = Integer.parseInt(splitLine[2]);

}

br.close();

输出:

KatalogObrazków

false

false

C:\Users\R/KatalogObrazków

编辑:

System.out.println();

for (char c : splitLine[0].toCharArray())

System.out.print((int) c + " ");

System.out.println();

for (char c : "KatalogObrazków".toCharArray())

System.out.print((int) c + " ");

System.out.println();

GOT ME:

65279 75 97 116 97 108 111 103 79 98 114 97 122 107 243 119

75 97 116 97 108 111 103 79 98 114 97 122 107 243 119

解决方法:

您可能在文件开头遇到了UTF-BOM.

它是隐形的,因为大多数编辑都隐藏它.很邪恶,对吧?

标签:java,string,equals

来源: https://codeday.me/bug/20190825/1715519.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值