{"@attributes":{"version":"2.0"},"channel":{"title":"String on \u9694\u53f6\u9ec4\u83ba Yanbin's Blog - \u8f6f\u4ef6\u7f16\u7a0b\u5b9e\u8df5","link":"https:\/\/yanbin.blog\/tags\/string\/","description":"Recent content in String on \u9694\u53f6\u9ec4\u83ba Yanbin's Blog - \u8f6f\u4ef6\u7f16\u7a0b\u5b9e\u8df5","generator":"Hugo -- gohugo.io","language":"en-us","managingEditor":"yabqiu@gmail.com (Yanbin Qiu)","webMaster":"yabqiu@gmail.com (Yanbin Qiu)","copyright":"Yanbin \u9694\u53f6\u9ec4\u83ba","lastBuildDate":"Thu, 24 Apr 2014 00:14:45 -0500","item":[{"title":"Java \u8bbe\u8ba1\u4e4b\u521d\u4e3a\u4f55\u5c31\u4e0d\u8ba9\u7528 == \u6bd4\u8f83\u4e24\u5b57\u7b26\u4e32\u5462\uff1f","link":"https:\/\/yanbin.blog\/java-why-cannot-compare-strings-with\/","pubDate":"Thu, 24 Apr 2014 00:14:45 -0500","author":"yabqiu@gmail.com (Yanbin Qiu)","guid":"https:\/\/yanbin.blog\/java-why-cannot-compare-strings-with\/","description":"\nJava \u7684\u5b57\u7b26\u4e32\u503c\u6bd4\u8f83\u4e0d\u80fd\u7528 == \u53f7\u8fd9\u4e2a\u8bbe\u8ba1\u4e0d\u77e5\u9053\u6700\u521d\u662f\u600e\u4e48\u8003\u8651\u7684\uff0c\u5b83\u6700\u5927\u7684\u8d21\u732e\u65e0\u7591\u662f\u6ecb\u751f\u4e86\u4e00\u4e2a\u957f\u4e45\u672a\u8870\u7684\u9762\u8bd5\u9898\uff0c\u52a0\u4e4b\u8fde Code Review \u90fd\u53ef\u80fd\u88ab\u5ffd\u7565\u6389\u7684 Bug\u3002\u672c\u6765\u4e24\u4e2a\u5b57\u7b26\u4e32\u7528\u7b49\u53f7\u76f8\u6bd4\u8f83\u662f\u6700\u81ea\u7136\u800c\u7136\u7684\u505a\u6cd5\uff0c\u7136\u800c\u5b83\u5374\u662f\u8981\u8feb\u4f7f\u6211\u4eec\u76f8\u4fe1\u60f3\u5f53\u7136\u5f88\u53ef\u80fd\u662f\u9519\u8bef\u7684\u90a3\u6837\u4e00\u4e2a\u9053\u7406\u3002<br\/>\n<br\/>\n\u6211\u4e00\u76f4\u8ba4\u4e3a Java \u7684\u5b57\u7b26\u4e32\u6bd4\u8f83\u503c\u4e0d\u80fd\u7528 == \u800c\u5fc5\u987b\u7528 equals() \u65b9\u6cd5\u662f\u4e2a\u4e0d\u6070\u5f53\u7684\u8bbe\u8ba1\uff0c\u8fd9\u4ece\u5176\u4ed6\u79cd\u79cd\u8bed\u8a00\u7684\u73b0\u5b9e\u505a\u6cd5(\u4eba\u5bb6\u90fd\u7528 == \u6bd4\u8f83\u503c)\u5c31\u77e5\u9053\u3002<br\/>\n<br\/>\n\u731c\u60f3\u4e00\u4e0b Java \u4e3a\u4f55\u8981\u8fd9\u6837\u5bf9\u5f85\u5b57\u7b26\u4e32\uff0c\u53ef\u80fd Java \u53c8\u60f3\u7c7b\u578b\u5168\u90e8\u5bf9\u8c61\u5316\uff0c\u540c\u65f6\u8003\u8651\u5230\u65b9\u4fbf\u6027\uff0c\u4ecd\u7136\u4fdd\u7559\u4e86 int, short, boolean \u7b49\u539f\u59cb\u7c7b\u578b\uff0c\u5b83\u4eec\u662f\u53ef\u4ee5\u7528 == \u6bd4\u8f83\u503c\uff0c\u5176\u4ed6\u771f\u6b63\u7684\u5bf9\u8c61\u7c7b\u578b\u7528 equals() \u65b9\u6cd5\u6bd4\u8f83\u4e5f\u662f\u65e0\u53ef\u539a\u975e\u7684\u3002\u8fd9\u65f6\u5019\u5939\u7f1d\u4e2d\u7684\u5b57\u7b26\u4e32\u5374\u88ab\u4e3a\u96be\u5230\u4e86\uff0c\u5b83\u90a3\u4e48\u7684\u5e38\u7528\uff0c\u8fd8\u5e38\u4ee5\u5b57\u9762\u91cf\u7684\u9762\u76ee\u51fa\u73b0\uff0c\u5b83\u66f4\u8be5\u662f\u4e2a\u57fa\u672c\u7c7b\u578b\uff0c\u800c\u5b9e\u4e3a\u5bf9\u8c61\u7c7b\u578b\uff0c\u56e0\u6b64\u4e0d\u88ab\u8ba4\u53ef\u7528 == \u76f4\u63a5\u6bd4\u8f83\u503c\uff0c \u800c\u9009\u62e9\u4e86\u7528 equals() \u65b9\u6cd5\u6765\u6bd4\u8f83\u5b57\u7b26\u4e32\u503c\u3002<br\/>\n<br\/>\n\u800c\u53e6\u4e00\u65b9\u9762\uff0c\u7531\u4e8e\u5b57\u7b26\u4e32\u662f\u591a\u4f8b\u7684\uff0c\u6240\u4ee5\u6709\u4e9b\u60c5\u51b5\u4e0b\u53c8\u66f4\u4ee4\u4eba\u8ff7\u60d1\uff0c\u6bd4\u5982\u4e0b\u9762\u7684\u79cd\u79cd\u60c5\u51b5"},{"title":"Java \u91cc\u628a InputStream \u8f6c\u6362\u6210 String \u7684\u51e0\u79cd\u65b9\u6cd5","link":"https:\/\/yanbin.blog\/java-convert-inputstream-to-string\/","pubDate":"Fri, 01 Feb 2013 05:35:57 -0600","author":"yabqiu@gmail.com (Yanbin Qiu)","guid":"https:\/\/yanbin.blog\/java-convert-inputstream-to-string\/","description":"\n\u6211\u4eec\u5728 Java \u4e2d\u7ecf\u5e38\u4f1a\u78b0\u5230\u5982\u4f55\u628a InputStream \u8f6c\u6362\u6210 String \u7684\u60c5\u5f62\uff0c\u6bd4\u5982\u4ece\u6587\u4ef6\u6216\u7f51\u7edc\u5f97\u5230\u4e00\u4e2a InputStream\uff0c\u9700\u8981\u8f6c\u6362\u6210\u5b57\u7b26\u4e32\u8f93\u51fa\u6216\u8d4b\u7ed9\u522b\u7684\u53d8\u91cf\u3002<\/p>\n<br\/>\n\u672a\u771f\u6b63\u5173\u6ce8\u8fd9\u4e2a\u95ee\u9898\u4e4b\u524d\u6211\u5e38\u7528\u7684\u529e\u6cd5\u5c31\u662f\u6309\u5b57\u8282\u4e00\u6b21\u6b21\u8bfb\u5230\u7f13\u51b2\u533a\uff0c\u6216\u662f\u5efa\u7acb BufferedReader \u9010\u884c\u8bfb\u53d6\u3002\u5176\u5b9e\u5927\u53ef\u4e0d\u5fc5\u8d39\u6b64\u5468\u6298\uff0c\u6211\u4eec\u53ef\u4ee5\u7528 Apache commons IOUtils\uff0c\u6216\u8005\u662f JDK 1.5 \u540e\u7684 Scanner\uff0c\u8fd8\u53ef\u7528 Google\u00a0 Guava \u5e93\u7684 CharStreams\u3002\u5230\u4e86 JDK7\uff0c\u82e5\u8981\u4ece\u6587\u4ef6\u4e2d\u76f4\u63a5\u5f97\u5230\u5b57\u7b26\u4e32\u8fd8\u80fd\u7528 java.nio.file.Files#readAllLines \u548c java.nio.file.Files#readAllBytes \u65b9\u6cd5\u3002<br\/><br\/>\n\u4e0b\u9762\u770b\u5404\u4e2a\u4f8b\u5b50\uff0c\u4e3a\u80fd\u591f\u5b9e\u9645\u7528\u8fd0\uff0c\u4f8b\u5b50\u5199\u5728 main \u65b9\u6cd5\u91cc\uff0c\u5e76\u4ece\u6587\u4ef6\u83b7\u5f97\u4e00\u4e2a InputStream\uff0c\u4ee3\u7801\u4e2d\u628a\u53ef\u80fd\u8981\u6355\u83b7\u7684\u5f02\u5e38\u629b\u51fa\u6765\u3002\u518d\u5c31\u662f\u6ce8\u610f\u5904\u7406\u8f93\u5165\u8f93\u51fa\u6d41\u65f6\u6709\u6d89\u53ca\u5230\u5b57\u7b26\u96c6\uff0c\u5b57\u7b26\u96c6\u4e71\u4e86\u5c31\u4e71\u7801\u4e86\uff0c\u9ed8\u8ba4\u5b57\u7b26\u96c6\u662f System.getProperty(\"file.encoding\")\uff0c\u901a\u5e38\u6211\u4eec\u90fd\u7528 UTF-8\uff0c\u5f02\u5e38 UnsupportedEncodingException \u7ee7\u627f\u81ea IOException\u3002<br\/><br\/>\n\u4e0b\u9762\u7684 6 \u4e2a\u65b9\u6cd5\u4e2d\u5e94\u8be5\u6709\u4e00\u4e2a\u4f60\u80fd\u770b\u5f97\u4e0a\u7684\u5427\uff0c\u7528 Groovy\uff0cScala \u7684\u9664\u5916\uff0c\u82e5\u672a\u627e\u5230\u4e00\u4e2a\u9042\u610f\u7684\uff0c\u544a\u8bc9\u6211\uff0c\u4f60\u6709\u597d\u529e\u6cd5\u66f4\u5e94\u8be5\u544a\u8bc9\u6211\u3002<br\/><br\/>\n<strong>1. \u4f7f\u7528 JDK 5 \u7684 Scanner<\/strong><br\/>"}]}}