确实那将是非常奇怪的:)您可以将上面的代码更改为此:
if ("debug_mode".equalsIgnoreCase("debug_mode")) debug_mode = true;确认它工作正常,然后再次检查为什么您
values[0]不是“ debug_mode”。
这就是我现在要检查的事情清单:
- 检查一下
values[0].length() == "debug_mode".length()
- 我非常怀疑,但是无论如何我还是要把它放在桌子上-您是否有机会使用Unipre?
- 您可以打印每个字符并
.equals()
在该字符和“ debug_mode”字符串的各个字符之间执行操作吗? - 如果这是在较大的项目中,则您可以在一个简单的Java项目中执行相同的操作并确认它可以在其中工作吗?
为了澄清,问题实际上是在使用
DataInputStream.readLine。从javadoc(http://download.oracle.com/javase/1.6.0/docs/api/java/io/DataInputStream.html):
readLine() Deprecated. This method does not properly convert bytes to characters. ...
它实际上以一种微妙的方式与Unipre有关-当
writeChar您实际编写两个字节
0以及
97字母的大端Unipre时
a。
这是一个独立的片段,显示了行为:
import java.io.*;import java.util.*;public class B { public static void main(String[] args) throws Exception { String os = "abc"; System.out.println("---- unipre, big-endian"); for(byte b: os.getBytes("UTF-16BE")) { System.out.println(b); } ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); for(char c: os.toCharArray()) { dos.writeChar(c); } byte[] ba = baos.toByteArray(); System.out.println("---- ba"); for(byte b: ba) { System.out.println(b); } ByteArrayInputStream bais = new ByteArrayInputStream(ba); DataInputStream dis = new DataInputStream(bais); System.out.println("---- dis"); String s = dis.readLine(); System.out.println(s); System.out.println("String length is " + s.length() + ", but you would expect " + os.length() + ", as that is what you see printed..."); }}故事的寓意-不要使用不推荐使用的API
…而且,空格是无声的杀手:http : //www.codinghorror.com/blog/2009/11/whitespace-the-
silent-killer.html



