java常用工具類(一)

一、String工具類

  1. package?com.mkyong.common;??
  2. ???
  3. import?java.util.ArrayList;??
  4. import?java.util.List;??
  5. ???
  6. /**?
  7. ?*??
  8. ?*?String工具類.?<br>?
  9. ?*??
  10. ?*?@author?宋立君?
  11. ?*?@date?2014年06月24日?
  12. ?*/??
  13. public?class?StringUtil?{??
  14. ???
  15. ????private?static?final?int?INDEX_NOT_FOUND?=?-1;??
  16. ????private?static?final?String?EMPTY?=?"";??
  17. ????/**?
  18. ?????*?<p>?
  19. ?????*?The?maximum?size?to?which?the?padding?constant(s)?can?expand.?
  20. ?????*?</p>?
  21. ?????*/??
  22. ????private?static?final?int?PAD_LIMIT?=?8192;??
  23. ???
  24. ????/**?
  25. ?????*?功能:將半角的符號轉換成全角符號.(即英文字符轉中文字符)?
  26. ?????*??
  27. ?????*?@author?宋立君?
  28. ?????*?@param?str?
  29. ?????*????????????源字符串?
  30. ?????*?@return?String?
  31. ?????*?@date?2014年06月24日?
  32. ?????*/??
  33. ????public?static?String?changeToFull(String?str)?{??
  34. ????????String?source?=?"1234567890!@#$%^&*()abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_=+\\|[];:'\",<.>/?";??
  35. ????????String[]?decode?=?{?"1",?"2",?"3",?"4",?"5",?"6",?"7",?"8",?"9",?"0",??
  36. ????????????????"!",?"@",?"#",?"$",?"%",?"︿",?"&",?"*",?"(",?")",?"a",?"b",??
  37. ????????????????"c",?"d",?"e",?"f",?"g",?"h",?"i",?"j",?"k",?"l",?"m",?"n",??
  38. ????????????????"o",?"p",?"q",?"r",?"s",?"t",?"u",?"v",?"w",?"x",?"y",?"z",??
  39. ????????????????"A",?"B",?"C",?"D",?"E",?"F",?"G",?"H",?"I",?"J",?"K",?"L",??
  40. ????????????????"M",?"N",?"O",?"P",?"Q",?"R",?"S",?"T",?"U",?"V",?"W",?"X",??
  41. ????????????????"Y",?"Z",?"-",?"_",?"=",?"+",?"\",?"|",?"【",?"】",?";",?":",??
  42. ????????????????"'",?"\"",?",",?"〈",?"。",?"〉",?"/",?"?"?};??
  43. ????????String?result?=?"";??
  44. ????????for?(int?i?=?0;?i?<?str.length();?i++)?{??
  45. ????????????int?pos?=?source.indexOf(str.charAt(i));??
  46. ????????????if?(pos?!=?-1)?{??
  47. ????????????????result?+=?decode[pos];??
  48. ????????????}?else?{??
  49. ????????????????result?+=?str.charAt(i);??
  50. ????????????}??
  51. ????????}??
  52. ????????return?result;??
  53. ????}??
  54. ???
  55. ????/**?
  56. ?????*?功能:cs串中是否一個都不包含字符數組searchChars中的字符。?
  57. ?????*??
  58. ?????*?@author?宋立君?
  59. ?????*?@param?cs?
  60. ?????*????????????字符串?
  61. ?????*?@param?searchChars?
  62. ?????*????????????字符數組?
  63. ?????*?@return?boolean?都不包含返回true,否則返回false。?
  64. ?????*?@date?2014年06月24日?
  65. ?????*/??
  66. ????public?static?boolean?containsNone(CharSequence?cs,?char...?searchChars)?{??
  67. ????????if?(cs?==?null?||?searchChars?==?null)?{??
  68. ????????????return?true;??
  69. ????????}??
  70. ????????int?csLen?=?cs.length();??
  71. ????????int?csLast?=?csLen?-?1;??
  72. ????????int?searchLen?=?searchChars.length;??
  73. ????????int?searchLast?=?searchLen?-?1;??
  74. ????????for?(int?i?=?0;?i?<?csLen;?i++)?{??
  75. ????????????char?ch?=?cs.charAt(i);??
  76. ????????????for?(int?j?=?0;?j?<?searchLen;?j++)?{??
  77. ????????????????if?(searchChars[j]?==?ch)?{??
  78. ????????????????????if?(Character.isHighSurrogate(ch))?{??
  79. ????????????????????????if?(j?==?searchLast)?{??
  80. ????????????????????????????//?missing?low?surrogate,?fine,?like??
  81. ????????????????????????????//?String.indexOf(String)??
  82. ????????????????????????????return?false;??
  83. ????????????????????????}??
  84. ????????????????????????if?(i?<?csLast??
  85. ????????????????????????????????&&?searchChars[j?+?1]?==?cs.charAt(i?+?1))?{??
  86. ????????????????????????????return?false;??
  87. ????????????????????????}??
  88. ????????????????????}?else?{??
  89. ????????????????????????//?ch?is?in?the?Basic?Multilingual?Plane??
  90. ????????????????????????return?false;??
  91. ????????????????????}??
  92. ????????????????}??
  93. ????????????}??
  94. ????????}??
  95. ????????return?true;??
  96. ????}??
  97. ???
  98. ????/**?
  99. ?????*?<p>?
  100. ?????*?編碼為Unicode,格式?'\u0020'.?
  101. ?????*?</p>?
  102. ?????*??
  103. ?????*?@author?宋立君?
  104. ?????*??
  105. ?????*?????????<pre>?
  106. ?????*???CharUtils.unicodeEscaped('?')?=?"\u0020"?
  107. ?????*???CharUtils.unicodeEscaped('A')?=?"\u0041"?
  108. ?????*?</pre>?
  109. ?????*??
  110. ?????*?@param?ch?
  111. ?????*????????????源字符串?
  112. ?????*?@return?轉碼后的字符串?
  113. ?????*?@date?2014年06月24日?
  114. ?????*/??
  115. ????public?static?String?unicodeEscaped(char?ch)?{??
  116. ????????if?(ch?<?0x10)?{??
  117. ????????????return?"\\u000"?+?Integer.toHexString(ch);??
  118. ????????}?else?if?(ch?<?0x100)?{??
  119. ????????????return?"\\u00"?+?Integer.toHexString(ch);??
  120. ????????}?else?if?(ch?<?0x1000)?{??
  121. ????????????return?"\\u0"?+?Integer.toHexString(ch);??
  122. ????????}??
  123. ????????return?"\\u"?+?Integer.toHexString(ch);??
  124. ????}??
  125. ???
  126. ????/**?
  127. ?????*?<p>?
  128. ?????*?進行tostring操作,如果傳入的是null,返回空字符串。?
  129. ?????*?</p>?
  130. ?????*?
  131. ?????*?<pre>?
  132. ?????*?ObjectUtils.toString(null)?????????=?""?
  133. ?????*?ObjectUtils.toString("")???????????=?""?
  134. ?????*?ObjectUtils.toString("bat")????????=?"bat"?
  135. ?????*?ObjectUtils.toString(Boolean.TRUE)?=?"true"?
  136. ?????*?</pre>?
  137. ?????*?
  138. ?????*?@param?obj?
  139. ?????*????????????源?
  140. ?????*?@return?String?
  141. ?????*/??
  142. ????public?static?String?toString(Object?obj)?{??
  143. ????????return?obj?==?null???""?:?obj.toString();??
  144. ????}??
  145. ???
  146. ????/**?
  147. ?????*?<p>?
  148. ?????*?進行tostring操作,如果傳入的是null,返回指定的默認值。?
  149. ?????*?</p>?
  150. ?????*?
  151. ?????*?<pre>?
  152. ?????*?ObjectUtils.toString(null,?null)???????????=?null?
  153. ?????*?ObjectUtils.toString(null,?"null")?????????=?"null"?
  154. ?????*?ObjectUtils.toString("",?"null")???????????=?""?
  155. ?????*?ObjectUtils.toString("bat",?"null")????????=?"bat"?
  156. ?????*?ObjectUtils.toString(Boolean.TRUE,?"null")?=?"true"?
  157. ?????*?</pre>?
  158. ?????*?
  159. ?????*?@param?obj?
  160. ?????*????????????源?
  161. ?????*?@param?nullStr?
  162. ?????*????????????如果obj為null時返回這個指定值?
  163. ?????*?@return?String?
  164. ?????*/??
  165. ????public?static?String?toString(Object?obj,?String?nullStr)?{??
  166. ????????return?obj?==?null???nullStr?:?obj.toString();??
  167. ????}??
  168. ???
  169. ????/**?
  170. ?????*?<p>?
  171. ?????*?只從源字符串中移除指定開頭子字符串.?
  172. ?????*?</p>?
  173. ?????*??
  174. ?????*?<pre>?
  175. ?????*?StringUtil.removeStart(null,?*)??????=?null?
  176. ?????*?StringUtil.removeStart("",?*)????????=?""?
  177. ?????*?StringUtil.removeStart(*,?null)??????=?*?
  178. ?????*?StringUtil.removeStart("www.domain.com",?"www.")???=?"domain.com"?
  179. ?????*?StringUtil.removeStart("domain.com",?"www.")???????=?"domain.com"?
  180. ?????*?StringUtil.removeStart("www.domain.com",?"domain")?=?"www.domain.com"?
  181. ?????*?StringUtil.removeStart("abc",?"")????=?"abc"?
  182. ?????*?</pre>?
  183. ?????*?
  184. ?????*?@param?str?
  185. ?????*????????????源字符串?
  186. ?????*?@param?remove?
  187. ?????*????????????將要被移除的子字符串?
  188. ?????*?@return?String?
  189. ?????*/??
  190. ????public?static?String?removeStart(String?str,?String?remove)?{??
  191. ????????if?(isEmpty(str)?||?isEmpty(remove))?{??
  192. ????????????return?str;??
  193. ????????}??
  194. ????????if?(str.startsWith(remove))?{??
  195. ????????????return?str.substring(remove.length());??
  196. ????????}??
  197. ????????return?str;??
  198. ????}??
  199. ???
  200. ????/**?
  201. ?????*?<p>?
  202. ?????*?只從源字符串中移除指定結尾的子字符串.?
  203. ?????*?</p>?
  204. ?????*??
  205. ?????*?<pre>?
  206. ?????*?StringUtil.removeEnd(null,?*)??????=?null?
  207. ?????*?StringUtil.removeEnd("",?*)????????=?""?
  208. ?????*?StringUtil.removeEnd(*,?null)??????=?*?
  209. ?????*?StringUtil.removeEnd("www.domain.com",?".com.")??=?"www.domain.com"?
  210. ?????*?StringUtil.removeEnd("www.domain.com",?".com")???=?"www.domain"?
  211. ?????*?StringUtil.removeEnd("www.domain.com",?"domain")?=?"www.domain.com"?
  212. ?????*?StringUtil.removeEnd("abc",?"")????=?"abc"?
  213. ?????*?</pre>?
  214. ?????*?
  215. ?????*?@param?str?
  216. ?????*????????????源字符串?
  217. ?????*?@param?remove?
  218. ?????*????????????將要被移除的子字符串?
  219. ?????*?@return?String?
  220. ?????*/??
  221. ????public?static?String?removeEnd(String?str,?String?remove)?{??
  222. ????????if?(isEmpty(str)?||?isEmpty(remove))?{??
  223. ????????????return?str;??
  224. ????????}??
  225. ????????if?(str.endsWith(remove))?{??
  226. ????????????return?str.substring(0,?str.length()?-?remove.length());??
  227. ????????}??
  228. ????????return?str;??
  229. ????}??
  230. ???
  231. ????/**?
  232. ?????*?<p>?
  233. ?????*?將一個字符串重復N次?
  234. ?????*?</p>?
  235. ?????*?
  236. ?????*?<pre>?
  237. ?????*?StringUtil.repeat(null,?2)?=?null?
  238. ?????*?StringUtil.repeat("",?0)???=?""?
  239. ?????*?StringUtil.repeat("",?2)???=?""?
  240. ?????*?StringUtil.repeat("a",?3)??=?"aaa"?
  241. ?????*?StringUtil.repeat("ab",?2)?=?"abab"?
  242. ?????*?StringUtil.repeat("a",?-2)?=?""?
  243. ?????*?</pre>?
  244. ?????*?
  245. ?????*?@param?str?
  246. ?????*????????????源字符串?
  247. ?????*?@param?repeat?
  248. ?????*????????????重復的次數?
  249. ?????*?@return?String?
  250. ?????*/??
  251. ????public?static?String?repeat(String?str,?int?repeat)?{??
  252. ????????//?Performance?tuned?for?2.0?(JDK1.4)??
  253. ???
  254. ????????if?(str?==?null)?{??
  255. ????????????return?null;??
  256. ????????}??
  257. ????????if?(repeat?<=?0)?{??
  258. ????????????return?EMPTY;??
  259. ????????}??
  260. ????????int?inputLength?=?str.length();??
  261. ????????if?(repeat?==?1?||?inputLength?==?0)?{??
  262. ????????????return?str;??
  263. ????????}??
  264. ????????if?(inputLength?==?1?&&?repeat?<=?PAD_LIMIT)?{??
  265. ????????????return?repeat(str.charAt(0),?repeat);??
  266. ????????}??
  267. ???
  268. ????????int?outputLength?=?inputLength?*?repeat;??
  269. ????????switch?(inputLength)?{??
  270. ????????case?1:??
  271. ????????????return?repeat(str.charAt(0),?repeat);??
  272. ????????case?2:??
  273. ????????????char?ch0?=?str.charAt(0);??
  274. ????????????char?ch1?=?str.charAt(1);??
  275. ????????????char[]?output2?=?new?char[outputLength];??
  276. ????????????for?(int?i?=?repeat?*?2?-?2;?i?>=?0;?i--,?i--)?{??
  277. ????????????????output2[i]?=?ch0;??
  278. ????????????????output2[i?+?1]?=?ch1;??
  279. ????????????}??
  280. ????????????return?new?String(output2);??
  281. ????????default:??
  282. ????????????StringBuilder?buf?=?new?StringBuilder(outputLength);??
  283. ????????????for?(int?i?=?0;?i?<?repeat;?i++)?{??
  284. ????????????????buf.append(str);??
  285. ????????????}??
  286. ????????????return?buf.toString();??
  287. ????????}??
  288. ????}??
  289. ???
  290. ????/**?
  291. ?????*?<p>?
  292. ?????*?將一個字符串重復N次,并且中間加上指定的分隔符?
  293. ?????*?</p>?
  294. ?????*?
  295. ?????*?<pre>?
  296. ?????*?StringUtil.repeat(null,?null,?2)?=?null?
  297. ?????*?StringUtil.repeat(null,?"x",?2)??=?null?
  298. ?????*?StringUtil.repeat("",?null,?0)???=?""?
  299. ?????*?StringUtil.repeat("",?"",?2)?????=?""?
  300. ?????*?StringUtil.repeat("",?"x",?3)????=?"xxx"?
  301. ?????*?StringUtil.repeat("?",?",?",?3)??=?"?,??,??"?
  302. ?????*?</pre>?
  303. ?????*?
  304. ?????*?@param?str?
  305. ?????*????????????源字符串?
  306. ?????*?@param?separator?
  307. ?????*????????????分隔符?
  308. ?????*?@param?repeat?
  309. ?????*????????????重復次數?
  310. ?????*?@return?String?
  311. ?????*/??
  312. ????public?static?String?repeat(String?str,?String?separator,?int?repeat)?{??
  313. ????????if?(str?==?null?||?separator?==?null)?{??
  314. ????????????return?repeat(str,?repeat);??
  315. ????????}?else?{??
  316. ????????????//?given?that?repeat(String,?int)?is?quite?optimized,?better?to?rely??
  317. ????????????//?on?it?than?try?and?splice?this?into?it??
  318. ????????????String?result?=?repeat(str?+?separator,?repeat);??
  319. ????????????return?removeEnd(result,?separator);??
  320. ????????}??
  321. ????}??
  322. ???
  323. ????/**?
  324. ?????*?<p>?
  325. ?????*?將某個字符重復N次.?
  326. ?????*?</p>?
  327. ?????*?
  328. ?????*?@param?ch?
  329. ?????*????????????某個字符?
  330. ?????*?@param?repeat?
  331. ?????*????????????重復次數?
  332. ?????*?@return?String?
  333. ?????*/??
  334. ????public?static?String?repeat(char?ch,?int?repeat)?{??
  335. ????????char[]?buf?=?new?char[repeat];??
  336. ????????for?(int?i?=?repeat?-?1;?i?>=?0;?i--)?{??
  337. ????????????buf[i]?=?ch;??
  338. ????????}??
  339. ????????return?new?String(buf);??
  340. ????}??
  341. ???
  342. ????/**?
  343. ?????*?<p>?
  344. ?????*?字符串長度達不到指定長度時,在字符串右邊補指定的字符.?
  345. ?????*?</p>?
  346. ?????*??
  347. ?????*?<pre>?
  348. ?????*?StringUtil.rightPad(null,?*,?*)?????=?null?
  349. ?????*?StringUtil.rightPad("",?3,?'z')?????=?"zzz"?
  350. ?????*?StringUtil.rightPad("bat",?3,?'z')??=?"bat"?
  351. ?????*?StringUtil.rightPad("bat",?5,?'z')??=?"batzz"?
  352. ?????*?StringUtil.rightPad("bat",?1,?'z')??=?"bat"?
  353. ?????*?StringUtil.rightPad("bat",?-1,?'z')?=?"bat"?
  354. ?????*?</pre>?
  355. ?????*?
  356. ?????*?@param?str?
  357. ?????*????????????源字符串?
  358. ?????*?@param?size?
  359. ?????*????????????指定的長度?
  360. ?????*?@param?padChar?
  361. ?????*????????????進行補充的字符?
  362. ?????*?@return?String?
  363. ?????*/??
  364. ????public?static?String?rightPad(String?str,?int?size,?char?padChar)?{??
  365. ????????if?(str?==?null)?{??
  366. ????????????return?null;??
  367. ????????}??
  368. ????????int?pads?=?size?-?str.length();??
  369. ????????if?(pads?<=?0)?{??
  370. ????????????return?str;?//?returns?original?String?when?possible??
  371. ????????}??
  372. ????????if?(pads?>?PAD_LIMIT)?{??
  373. ????????????return?rightPad(str,?size,?String.valueOf(padChar));??
  374. ????????}??
  375. ????????return?str.concat(repeat(padChar,?pads));??
  376. ????}??
  377. ???
  378. ????/**?
  379. ?????*?<p>?
  380. ?????*?擴大字符串長度,從左邊補充指定字符?
  381. ?????*?</p>?
  382. ?????*??
  383. ?????*?<pre>?
  384. ?????*?StringUtil.rightPad(null,?*,?*)??????=?null?
  385. ?????*?StringUtil.rightPad("",?3,?"z")??????=?"zzz"?
  386. ?????*?StringUtil.rightPad("bat",?3,?"yz")??=?"bat"?
  387. ?????*?StringUtil.rightPad("bat",?5,?"yz")??=?"batyz"?
  388. ?????*?StringUtil.rightPad("bat",?8,?"yz")??=?"batyzyzy"?
  389. ?????*?StringUtil.rightPad("bat",?1,?"yz")??=?"bat"?
  390. ?????*?StringUtil.rightPad("bat",?-1,?"yz")?=?"bat"?
  391. ?????*?StringUtil.rightPad("bat",?5,?null)??=?"bat??"?
  392. ?????*?StringUtil.rightPad("bat",?5,?"")????=?"bat??"?
  393. ?????*?</pre>?
  394. ?????*?
  395. ?????*?@param?str?
  396. ?????*????????????源字符串?
  397. ?????*?@param?size?
  398. ?????*????????????擴大后的長度?
  399. ?????*?@param?padStr?
  400. ?????*????????????在右邊補充的字符串?
  401. ?????*?@return?String?
  402. ?????*/??
  403. ????public?static?String?rightPad(String?str,?int?size,?String?padStr)?{??
  404. ????????if?(str?==?null)?{??
  405. ????????????return?null;??
  406. ????????}??
  407. ????????if?(isEmpty(padStr))?{??
  408. ????????????padStr?=?"?";??
  409. ????????}??
  410. ????????int?padLen?=?padStr.length();??
  411. ????????int?strLen?=?str.length();??
  412. ????????int?pads?=?size?-?strLen;??
  413. ????????if?(pads?<=?0)?{??
  414. ????????????return?str;?//?returns?original?String?when?possible??
  415. ????????}??
  416. ????????if?(padLen?==?1?&&?pads?<=?PAD_LIMIT)?{??
  417. ????????????return?rightPad(str,?size,?padStr.charAt(0));??
  418. ????????}??
  419. ???
  420. ????????if?(pads?==?padLen)?{??
  421. ????????????return?str.concat(padStr);??
  422. ????????}?else?if?(pads?<?padLen)?{??
  423. ????????????return?str.concat(padStr.substring(0,?pads));??
  424. ????????}?else?{??
  425. ????????????char[]?padding?=?new?char[pads];??
  426. ????????????char[]?padChars?=?padStr.toCharArray();??
  427. ????????????for?(int?i?=?0;?i?<?pads;?i++)?{??
  428. ????????????????padding[i]?=?padChars[i?%?padLen];??
  429. ????????????}??
  430. ????????????return?str.concat(new?String(padding));??
  431. ????????}??
  432. ????}??
  433. ???
  434. ????/**?
  435. ?????*?<p>?
  436. ?????*?擴大字符串長度,從左邊補充空格?
  437. ?????*?</p>?
  438. ?????*?
  439. ?????*?<pre>?
  440. ?????*?StringUtil.leftPad(null,?*)???=?null?
  441. ?????*?StringUtil.leftPad("",?3)?????=?"???"?
  442. ?????*?StringUtil.leftPad("bat",?3)??=?"bat"?
  443. ?????*?StringUtil.leftPad("bat",?5)??=?"??bat"?
  444. ?????*?StringUtil.leftPad("bat",?1)??=?"bat"?
  445. ?????*?StringUtil.leftPad("bat",?-1)?=?"bat"?
  446. ?????*?</pre>?
  447. ?????*?
  448. ?????*?@param?str?
  449. ?????*????????????源字符串?
  450. ?????*?@param?size?
  451. ?????*????????????擴大后的長度?
  452. ?????*?@return?String?
  453. ?????*/??
  454. ????public?static?String?leftPad(String?str,?int?size)?{??
  455. ????????return?leftPad(str,?size,?'?');??
  456. ????}??
  457. ???
  458. ????/**?
  459. ?????*?<p>?
  460. ?????*?擴大字符串長度,從左邊補充指定的字符?
  461. ?????*?</p>?
  462. ?????*?
  463. ?????*?<pre>?
  464. ?????*?StringUtil.leftPad(null,?*,?*)?????=?null?
  465. ?????*?StringUtil.leftPad("",?3,?'z')?????=?"zzz"?
  466. ?????*?StringUtil.leftPad("bat",?3,?'z')??=?"bat"?
  467. ?????*?StringUtil.leftPad("bat",?5,?'z')??=?"zzbat"?
  468. ?????*?StringUtil.leftPad("bat",?1,?'z')??=?"bat"?
  469. ?????*?StringUtil.leftPad("bat",?-1,?'z')?=?"bat"?
  470. ?????*?</pre>?
  471. ?????*?
  472. ?????*?@param?str?
  473. ?????*????????????源字符串?
  474. ?????*?@param?size?
  475. ?????*????????????擴大后的長度?
  476. ?????*?@param?padStr?
  477. ?????*????????????補充的字符?
  478. ?????*?@return?String?
  479. ?????*/??
  480. ????public?static?String?leftPad(String?str,?int?size,?char?padChar)?{??
  481. ????????if?(str?==?null)?{??
  482. ????????????return?null;??
  483. ????????}??
  484. ????????int?pads?=?size?-?str.length();??
  485. ????????if?(pads?<=?0)?{??
  486. ????????????return?str;?//?returns?original?String?when?possible??
  487. ????????}??
  488. ????????if?(pads?>?PAD_LIMIT)?{??
  489. ????????????return?leftPad(str,?size,?String.valueOf(padChar));??
  490. ????????}??
  491. ????????return?repeat(padChar,?pads).concat(str);??
  492. ????}??
  493. ???
  494. ????/**?
  495. ?????*?<p>?
  496. ?????*?擴大字符串長度,從左邊補充指定的字符?
  497. ?????*?</p>?
  498. ?????*??
  499. ?????*?<pre>?
  500. ?????*?StringUtil.leftPad(null,?*,?*)??????=?null?
  501. ?????*?StringUtil.leftPad("",?3,?"z")??????=?"zzz"?
  502. ?????*?StringUtil.leftPad("bat",?3,?"yz")??=?"bat"?
  503. ?????*?StringUtil.leftPad("bat",?5,?"yz")??=?"yzbat"?
  504. ?????*?StringUtil.leftPad("bat",?8,?"yz")??=?"yzyzybat"?
  505. ?????*?StringUtil.leftPad("bat",?1,?"yz")??=?"bat"?
  506. ?????*?StringUtil.leftPad("bat",?-1,?"yz")?=?"bat"?
  507. ?????*?StringUtil.leftPad("bat",?5,?null)??=?"??bat"?
  508. ?????*?StringUtil.leftPad("bat",?5,?"")????=?"??bat"?
  509. ?????*?</pre>?
  510. ?????*?
  511. ?????*?@param?str?
  512. ?????*????????????源字符串?
  513. ?????*?@param?size?
  514. ?????*????????????擴大后的長度?
  515. ?????*?@param?padStr?
  516. ?????*????????????補充的字符串?
  517. ?????*?@return?String?
  518. ?????*/??
  519. ????public?static?String?leftPad(String?str,?int?size,?String?padStr)?{??
  520. ????????if?(str?==?null)?{??
  521. ????????????return?null;??
  522. ????????}??
  523. ????????if?(isEmpty(padStr))?{??
  524. ????????????padStr?=?"?";??
  525. ????????}??
  526. ????????int?padLen?=?padStr.length();??
  527. ????????int?strLen?=?str.length();??
  528. ????????int?pads?=?size?-?strLen;??
  529. ????????if?(pads?<=?0)?{??
  530. ????????????return?str;?//?returns?original?String?when?possible??
  531. ????????}??
  532. ????????if?(padLen?==?1?&&?pads?<=?PAD_LIMIT)?{??
  533. ????????????return?leftPad(str,?size,?padStr.charAt(0));??
  534. ????????}??
  535. ???
  536. ????????if?(pads?==?padLen)?{??
  537. ????????????return?padStr.concat(str);??
  538. ????????}?else?if?(pads?<?padLen)?{??
  539. ????????????return?padStr.substring(0,?pads).concat(str);??
  540. ????????}?else?{??
  541. ????????????char[]?padding?=?new?char[pads];??
  542. ????????????char[]?padChars?=?padStr.toCharArray();??
  543. ????????????for?(int?i?=?0;?i?<?pads;?i++)?{??
  544. ????????????????padding[i]?=?padChars[i?%?padLen];??
  545. ????????????}??
  546. ????????????return?new?String(padding).concat(str);??
  547. ????????}??
  548. ????}??
  549. ???
  550. ????/**?
  551. ?????*?<p>?
  552. ?????*?擴大字符串長度并將現在的字符串居中,被擴大部分用空格填充。?
  553. ?????*?<p>?
  554. ?????*??
  555. ?????*?<pre>?
  556. ?????*?StringUtil.center(null,?*)???=?null?
  557. ?????*?StringUtil.center("",?4)?????=?"????"?
  558. ?????*?StringUtil.center("ab",?-1)??=?"ab"?
  559. ?????*?StringUtil.center("ab",?4)???=?"?ab?"?
  560. ?????*?StringUtil.center("abcd",?2)?=?"abcd"?
  561. ?????*?StringUtil.center("a",?4)????=?"?a??"?
  562. ?????*?</pre>?
  563. ?????*?
  564. ?????*?@param?str?
  565. ?????*????????????源字符串?
  566. ?????*?@param?size?
  567. ?????*????????????擴大后的長度?
  568. ?????*?@return?String?
  569. ?????*/??
  570. ????public?static?String?center(String?str,?int?size)?{??
  571. ????????return?center(str,?size,?'?');??
  572. ????}??
  573. ???
  574. ????/**?
  575. ?????*?<p>?
  576. ?????*?將字符串長度修改為指定長度,并進行居中顯示。?
  577. ?????*?</p>?
  578. ?????*?
  579. ?????*?<pre>?
  580. ?????*?StringUtil.center(null,?*,?*)?????=?null?
  581. ?????*?StringUtil.center("",?4,?'?')?????=?"????"?
  582. ?????*?StringUtil.center("ab",?-1,?'?')??=?"ab"?
  583. ?????*?StringUtil.center("ab",?4,?'?')???=?"?ab"?
  584. ?????*?StringUtil.center("abcd",?2,?'?')?=?"abcd"?
  585. ?????*?StringUtil.center("a",?4,?'?')????=?"?a??"?
  586. ?????*?StringUtil.center("a",?4,?'y')????=?"yayy"?
  587. ?????*?</pre>?
  588. ?????*?
  589. ?????*?@param?str?
  590. ?????*????????????源字符串?
  591. ?????*?@param?size?
  592. ?????*????????????指定的長度?
  593. ?????*?@param?padStr?
  594. ?????*????????????長度不夠時補充的字符串?
  595. ?????*?@return?String?
  596. ?????*?@throws?IllegalArgumentException?
  597. ?????*?????????????如果被補充字符串為?null或者?empty?
  598. ?????*/??
  599. ????public?static?String?center(String?str,?int?size,?char?padChar)?{??
  600. ????????if?(str?==?null?||?size?<=?0)?{??
  601. ????????????return?str;??
  602. ????????}??
  603. ????????int?strLen?=?str.length();??
  604. ????????int?pads?=?size?-?strLen;??
  605. ????????if?(pads?<=?0)?{??
  606. ????????????return?str;??
  607. ????????}??
  608. ????????str?=?leftPad(str,?strLen?+?pads?/?2,?padChar);??
  609. ????????str?=?rightPad(str,?size,?padChar);??
  610. ????????return?str;??
  611. ????}??
  612. ???
  613. ????/**?
  614. ?????*?<p>?
  615. ?????*?將字符串長度修改為指定長度,并進行居中顯示。?
  616. ?????*?</p>?
  617. ?????*?
  618. ?????*?<pre>?
  619. ?????*?StringUtil.center(null,?*,?*)?????=?null?
  620. ?????*?StringUtil.center("",?4,?"?")?????=?"????"?
  621. ?????*?StringUtil.center("ab",?-1,?"?")??=?"ab"?
  622. ?????*?StringUtil.center("ab",?4,?"?")???=?"?ab"?
  623. ?????*?StringUtil.center("abcd",?2,?"?")?=?"abcd"?
  624. ?????*?StringUtil.center("a",?4,?"?")????=?"?a??"?
  625. ?????*?StringUtil.center("a",?4,?"yz")???=?"yayz"?
  626. ?????*?StringUtil.center("abc",?7,?null)?=?"??abc??"?
  627. ?????*?StringUtil.center("abc",?7,?"")???=?"??abc??"?
  628. ?????*?</pre>?
  629. ?????*?
  630. ?????*?@param?str?
  631. ?????*????????????源字符串?
  632. ?????*?@param?size?
  633. ?????*????????????指定的長度?
  634. ?????*?@param?padStr?
  635. ?????*????????????長度不夠時補充的字符串?
  636. ?????*?@return?String?
  637. ?????*?@throws?IllegalArgumentException?
  638. ?????*?????????????如果被補充字符串為?null或者?empty?
  639. ?????*/??
  640. ????public?static?String?center(String?str,?int?size,?String?padStr)?{??
  641. ????????if?(str?==?null?||?size?<=?0)?{??
  642. ????????????return?str;??
  643. ????????}??
  644. ????????if?(isEmpty(padStr))?{??
  645. ????????????padStr?=?"?";??
  646. ????????}??
  647. ????????int?strLen?=?str.length();??
  648. ????????int?pads?=?size?-?strLen;??
  649. ????????if?(pads?<=?0)?{??
  650. ????????????return?str;??
  651. ????????}??
  652. ????????str?=?leftPad(str,?strLen?+?pads?/?2,?padStr);??
  653. ????????str?=?rightPad(str,?size,?padStr);??
  654. ????????return?str;??
  655. ????}??
  656. ???
  657. ????/**?
  658. ?????*?<p>?
  659. ?????*?檢查字符串是否全部為小寫.?
  660. ?????*?</p>?
  661. ?????*??
  662. ?????*?<pre>?
  663. ?????*?StringUtil.isAllLowerCase(null)???=?false?
  664. ?????*?StringUtil.isAllLowerCase("")?????=?false?
  665. ?????*?StringUtil.isAllLowerCase("??")???=?false?
  666. ?????*?StringUtil.isAllLowerCase("abc")??=?true?
  667. ?????*?StringUtil.isAllLowerCase("abC")?=?false?
  668. ?????*?</pre>?
  669. ?????*?
  670. ?????*?@param?cs?
  671. ?????*????????????源字符串?
  672. ?????*?@return?String?
  673. ?????*/??
  674. ????public?static?boolean?isAllLowerCase(String?cs)?{??
  675. ????????if?(cs?==?null?||?isEmpty(cs))?{??
  676. ????????????return?false;??
  677. ????????}??
  678. ????????int?sz?=?cs.length();??
  679. ????????for?(int?i?=?0;?i?<?sz;?i++)?{??
  680. ????????????if?(Character.isLowerCase(cs.charAt(i))?==?false)?{??
  681. ????????????????return?false;??
  682. ????????????}??
  683. ????????}??
  684. ????????return?true;??
  685. ????}??
  686. ???
  687. ????/**?
  688. ?????*?<p>?
  689. ?????*?檢查是否都是大寫.?
  690. ?????*?</p>?
  691. ?????*??
  692. ?????*?<pre>?
  693. ?????*?StringUtil.isAllUpperCase(null)???=?false?
  694. ?????*?StringUtil.isAllUpperCase("")?????=?false?
  695. ?????*?StringUtil.isAllUpperCase("??")???=?false?
  696. ?????*?StringUtil.isAllUpperCase("ABC")??=?true?
  697. ?????*?StringUtil.isAllUpperCase("aBC")?=?false?
  698. ?????*?</pre>?
  699. ?????*?
  700. ?????*?@param?cs?
  701. ?????*????????????源字符串?
  702. ?????*?@return?String?
  703. ?????*/??
  704. ????public?static?boolean?isAllUpperCase(String?cs)?{??
  705. ????????if?(cs?==?null?||?StringUtil.isEmpty(cs))?{??
  706. ????????????return?false;??
  707. ????????}??
  708. ????????int?sz?=?cs.length();??
  709. ????????for?(int?i?=?0;?i?<?sz;?i++)?{??
  710. ????????????if?(Character.isUpperCase(cs.charAt(i))?==?false)?{??
  711. ????????????????return?false;??
  712. ????????????}??
  713. ????????}??
  714. ????????return?true;??
  715. ????}??
  716. ???
  717. ????/**?
  718. ?????*?<p>?
  719. ?????*?反轉字符串.?
  720. ?????*?</p>?
  721. ?????*??
  722. ?????*?<pre>?
  723. ?????*?StringUtil.reverse(null)??=?null?
  724. ?????*?StringUtil.reverse("")????=?""?
  725. ?????*?StringUtil.reverse("bat")?=?"tab"?
  726. ?????*?</pre>?
  727. ?????*?
  728. ?????*?@param?str?
  729. ?????*????????????源字符串?
  730. ?????*?@return?String?
  731. ?????*/??
  732. ????public?static?String?reverse(String?str)?{??
  733. ????????if?(str?==?null)?{??
  734. ????????????return?null;??
  735. ????????}??
  736. ????????return?new?StringBuilder(str).reverse().toString();??
  737. ????}??
  738. ???
  739. ????/**?
  740. ?????*?<p>?
  741. ?????*?字符串達不到一定長度時在右邊補空白.?
  742. ?????*?</p>?
  743. ?????*??
  744. ?????*?<pre>?
  745. ?????*?StringUtil.rightPad(null,?*)???=?null?
  746. ?????*?StringUtil.rightPad("",?3)?????=?"???"?
  747. ?????*?StringUtil.rightPad("bat",?3)??=?"bat"?
  748. ?????*?StringUtil.rightPad("bat",?5)??=?"bat??"?
  749. ?????*?StringUtil.rightPad("bat",?1)??=?"bat"?
  750. ?????*?StringUtil.rightPad("bat",?-1)?=?"bat"?
  751. ?????*?</pre>?
  752. ?????*?
  753. ?????*?@param?str?
  754. ?????*????????????源字符串?
  755. ?????*?@param?size?
  756. ?????*????????????指定的長度?
  757. ?????*?@return?String?
  758. ?????*/??
  759. ????public?static?String?rightPad(String?str,?int?size)?{??
  760. ????????return?rightPad(str,?size,?'?');??
  761. ????}??
  762. ???
  763. ????/**?
  764. ?????*?從右邊截取字符串.</p>?
  765. ?????*??
  766. ?????*?<pre>?
  767. ?????*?StringUtil.right(null,?*)????=?null?
  768. ?????*?StringUtil.right(*,?-ve)?????=?""?
  769. ?????*?StringUtil.right("",?*)??????=?""?
  770. ?????*?StringUtil.right("abc",?0)???=?""?
  771. ?????*?StringUtil.right("abc",?2)???=?"bc"?
  772. ?????*?StringUtil.right("abc",?4)???=?"abc"?
  773. ?????*?</pre>?
  774. ?????*??
  775. ?????*?@param?str?
  776. ?????*????????????源字符串?
  777. ?????*?@param?len?
  778. ?????*????????????長度?
  779. ?????*?@return?String?
  780. ?????*/??
  781. ????public?static?String?right(String?str,?int?len)?{??
  782. ????????if?(str?==?null)?{??
  783. ????????????return?null;??
  784. ????????}??
  785. ????????if?(len?<?0)?{??
  786. ????????????return?EMPTY;??
  787. ????????}??
  788. ????????if?(str.length()?<=?len)?{??
  789. ????????????return?str;??
  790. ????????}??
  791. ????????return?str.substring(str.length()?-?len);??
  792. ????}??
  793. ???
  794. ????/**?
  795. ?????*?<p>?
  796. ?????*?截取一個字符串的前幾個.?
  797. ?????*?</p>?
  798. ?????*??
  799. ?????*?<pre>?
  800. ?????*?StringUtil.left(null,?*)????=?null?
  801. ?????*?StringUtil.left(*,?-ve)?????=?""?
  802. ?????*?StringUtil.left("",?*)??????=?""?
  803. ?????*?StringUtil.left("abc",?0)???=?""?
  804. ?????*?StringUtil.left("abc",?2)???=?"ab"?
  805. ?????*?StringUtil.left("abc",?4)???=?"abc"?
  806. ?????*?</pre>?
  807. ?????*??
  808. ?????*?@param?str?
  809. ?????*????????????源字符串?
  810. ?????*?@param?len?
  811. ?????*????????????截取的長度?
  812. ?????*?@return?the?String?
  813. ?????*/??
  814. ????public?static?String?left(String?str,?int?len)?{??
  815. ????????if?(str?==?null)?{??
  816. ????????????return?null;??
  817. ????????}??
  818. ????????if?(len?<?0)?{??
  819. ????????????return?EMPTY;??
  820. ????????}??
  821. ????????if?(str.length()?<=?len)?{??
  822. ????????????return?str;??
  823. ????????}??
  824. ????????return?str.substring(0,?len);??
  825. ????}??
  826. ???
  827. ????/**?
  828. ?????*?<p>?
  829. ?????*?得到tag字符串中間的子字符串,只返回第一個匹配項。?
  830. ?????*?</p>?
  831. ?????*??
  832. ?????*?<pre>?
  833. ?????*?StringUtil.substringBetween(null,?*)????????????=?null?
  834. ?????*?StringUtil.substringBetween("",?"")?????????????=?""?
  835. ?????*?StringUtil.substringBetween("",?"tag")??????????=?null?
  836. ?????*?StringUtil.substringBetween("tagabctag",?null)??=?null?
  837. ?????*?StringUtil.substringBetween("tagabctag",?"")????=?""?
  838. ?????*?StringUtil.substringBetween("tagabctag",?"tag")?=?"abc"?
  839. ?????*?</pre>?
  840. ?????*??
  841. ?????*?@param?str?
  842. ?????*????????????源字符串。?
  843. ?????*?@param?tag?
  844. ?????*????????????標識字符串。?
  845. ?????*?@return?String?子字符串,?如果沒有符合要求的,返回{@code?null}。?
  846. ?????*/??
  847. ????public?static?String?substringBetween(String?str,?String?tag)?{??
  848. ????????return?substringBetween(str,?tag,?tag);??
  849. ????}??
  850. ???
  851. ????/**?
  852. ?????*?<p>?
  853. ?????*?得到兩個字符串中間的子字符串,只返回第一個匹配項。?
  854. ?????*?</p>?
  855. ?????*??
  856. ?????*?<pre>?
  857. ?????*?StringUtil.substringBetween("wx[b]yz",?"[",?"]")?=?"b"?
  858. ?????*?StringUtil.substringBetween(null,?*,?*)??????????=?null?
  859. ?????*?StringUtil.substringBetween(*,?null,?*)??????????=?null?
  860. ?????*?StringUtil.substringBetween(*,?*,?null)??????????=?null?
  861. ?????*?StringUtil.substringBetween("",?"",?"")??????????=?""?
  862. ?????*?StringUtil.substringBetween("",?"",?"]")?????????=?null?
  863. ?????*?StringUtil.substringBetween("",?"[",?"]")????????=?null?
  864. ?????*?StringUtil.substringBetween("yabcz",?"",?"")?????=?""?
  865. ?????*?StringUtil.substringBetween("yabcz",?"y",?"z")???=?"abc"?
  866. ?????*?StringUtil.substringBetween("yabczyabcz",?"y",?"z")???=?"abc"?
  867. ?????*?</pre>?
  868. ?????*??
  869. ?????*?@param?str?
  870. ?????*????????????源字符串?
  871. ?????*?@param?open?
  872. ?????*????????????起字符串。?
  873. ?????*?@param?close?
  874. ?????*????????????末字符串。?
  875. ?????*?@return?String?子字符串,?如果沒有符合要求的,返回{@code?null}。?
  876. ?????*/??
  877. ????public?static?String?substringBetween(String?str,?String?open,?String?close)?{??
  878. ????????if?(str?==?null?||?open?==?null?||?close?==?null)?{??
  879. ????????????return?null;??
  880. ????????}??
  881. ????????int?start?=?str.indexOf(open);??
  882. ????????if?(start?!=?INDEX_NOT_FOUND)?{??
  883. ????????????int?end?=?str.indexOf(close,?start?+?open.length());??
  884. ????????????if?(end?!=?INDEX_NOT_FOUND)?{??
  885. ????????????????return?str.substring(start?+?open.length(),?end);??
  886. ????????????}??
  887. ????????}??
  888. ????????return?null;??
  889. ????}??
  890. ???
  891. ????/**?
  892. ?????*?<p>?
  893. ?????*?得到兩個字符串中間的子字符串,所有匹配項組合為數組并返回。?
  894. ?????*?</p>?
  895. ?????*??
  896. ?????*?<pre>?
  897. ?????*?StringUtil.substringsBetween("[a][b][c]",?"[",?"]")?=?["a","b","c"]?
  898. ?????*?StringUtil.substringsBetween(null,?*,?*)????????????=?null?
  899. ?????*?StringUtil.substringsBetween(*,?null,?*)????????????=?null?
  900. ?????*?StringUtil.substringsBetween(*,?*,?null)????????????=?null?
  901. ?????*?StringUtil.substringsBetween("",?"[",?"]")??????????=?[]?
  902. ?????*?</pre>?
  903. ?????*?
  904. ?????*?@param?str?
  905. ?????*????????????源字符串?
  906. ?????*?@param?open?
  907. ?????*????????????起字符串。?
  908. ?????*?@param?close?
  909. ?????*????????????末字符串。?
  910. ?????*?@return?String?子字符串數組,?如果沒有符合要求的,返回{@code?null}。?
  911. ?????*/??
  912. ????public?static?String[]?substringsBetween(String?str,?String?open,??
  913. ????????????String?close)?{??
  914. ????????if?(str?==?null?||?isEmpty(open)?||?isEmpty(close))?{??
  915. ????????????return?null;??
  916. ????????}??
  917. ????????int?strLen?=?str.length();??
  918. ????????if?(strLen?==?0)?{??
  919. ????????????return?new?String[0];??
  920. ????????}??
  921. ????????int?closeLen?=?close.length();??
  922. ????????int?openLen?=?open.length();??
  923. ????????List<String>?list?=?new?ArrayList<String>();??
  924. ????????int?pos?=?0;??
  925. ????????while?(pos?<?strLen?-?closeLen)?{??
  926. ????????????int?start?=?str.indexOf(open,?pos);??
  927. ????????????if?(start?<?0)?{??
  928. ????????????????break;??
  929. ????????????}??
  930. ????????????start?+=?openLen;??
  931. ????????????int?end?=?str.indexOf(close,?start);??
  932. ????????????if?(end?<?0)?{??
  933. ????????????????break;??
  934. ????????????}??
  935. ????????????list.add(str.substring(start,?end));??
  936. ????????????pos?=?end?+?closeLen;??
  937. ????????}??
  938. ????????if?(list.isEmpty())?{??
  939. ????????????return?null;??
  940. ????????}??
  941. ????????return?list.toArray(new?String[list.size()]);??
  942. ????}??
  943. ???
  944. ????/**?
  945. ?????*?功能:切換字符串中的所有字母大小寫。<br/>?
  946. ?????*??
  947. ?????*?<pre>?
  948. ?????*?StringUtil.swapCase(null)?????????????????=?null?
  949. ?????*?StringUtil.swapCase("")???????????????????=?""?
  950. ?????*?StringUtil.swapCase("The?dog?has?a?BONE")?=?"tHE?DOG?HAS?A?bone"?
  951. ?????*?</pre>?
  952. ?????*??
  953. ?????*?
  954. ?????*?@param?str?
  955. ?????*????????????源字符串?
  956. ?????*?@return?String?
  957. ?????*/??
  958. ????public?static?String?swapCase(String?str)?{??
  959. ????????if?(StringUtil.isEmpty(str))?{??
  960. ????????????return?str;??
  961. ????????}??
  962. ????????char[]?buffer?=?str.toCharArray();??
  963. ???
  964. ????????boolean?whitespace?=?true;??
  965. ???
  966. ????????for?(int?i?=?0;?i?<?buffer.length;?i++)?{??
  967. ????????????char?ch?=?buffer[i];??
  968. ????????????if?(Character.isUpperCase(ch))?{??
  969. ????????????????buffer[i]?=?Character.toLowerCase(ch);??
  970. ????????????????whitespace?=?false;??
  971. ????????????}?else?if?(Character.isTitleCase(ch))?{??
  972. ????????????????buffer[i]?=?Character.toLowerCase(ch);??
  973. ????????????????whitespace?=?false;??
  974. ????????????}?else?if?(Character.isLowerCase(ch))?{??
  975. ????????????????if?(whitespace)?{??
  976. ????????????????????buffer[i]?=?Character.toTitleCase(ch);??
  977. ????????????????????whitespace?=?false;??
  978. ????????????????}?else?{??
  979. ????????????????????buffer[i]?=?Character.toUpperCase(ch);??
  980. ????????????????}??
  981. ????????????}?else?{??
  982. ????????????????whitespace?=?Character.isWhitespace(ch);??
  983. ????????????}??
  984. ????????}??
  985. ????????return?new?String(buffer);??
  986. ????}??
  987. ???
  988. ????/**?
  989. ?????*?功能:截取出最后一個標志位之后的字符串.<br/>?
  990. ?????*?如果sourceStr為empty或者expr為null,直接返回源字符串。<br/>?
  991. ?????*?如果expr長度為0,直接返回sourceStr。<br/>?
  992. ?????*?如果expr在sourceStr中不存在,直接返回sourceStr。<br/>?
  993. ?????*??
  994. ?????*?@author?宋立君?
  995. ?????*?@date?2014年06月24日?
  996. ?????*?@param?sourceStr?
  997. ?????*????????????被截取的字符串?
  998. ?????*?@param?expr?
  999. ?????*????????????分隔符?
  1000. ?????*?@return?String?
  1001. ?????*/??
  1002. ????public?static?String?substringAfterLast(String?sourceStr,?String?expr)?{??
  1003. ????????if?(isEmpty(sourceStr)?||?expr?==?null)?{??
  1004. ????????????return?sourceStr;??
  1005. ????????}??
  1006. ????????if?(expr.length()?==?0)?{??
  1007. ????????????return?sourceStr;??
  1008. ????????}??
  1009. ???
  1010. ????????int?pos?=?sourceStr.lastIndexOf(expr);??
  1011. ????????if?(pos?==?-1)?{??
  1012. ????????????return?sourceStr;??
  1013. ????????}??
  1014. ????????return?sourceStr.substring(pos?+?expr.length());??
  1015. ????}??
  1016. ???
  1017. ????/**?
  1018. ?????*?功能:截取出最后一個標志位之前的字符串.<br/>?
  1019. ?????*?如果sourceStr為empty或者expr為null,直接返回源字符串。<br/>?
  1020. ?????*?如果expr長度為0,直接返回sourceStr。<br/>?
  1021. ?????*?如果expr在sourceStr中不存在,直接返回sourceStr。<br/>?
  1022. ?????*??
  1023. ?????*?@author?宋立君?
  1024. ?????*?@date?2014年06月24日?
  1025. ?????*?@param?sourceStr?
  1026. ?????*????????????被截取的字符串?
  1027. ?????*?@param?expr?
  1028. ?????*????????????分隔符?
  1029. ?????*?@return?String?
  1030. ?????*/??
  1031. ????public?static?String?substringBeforeLast(String?sourceStr,?String?expr)?{??
  1032. ????????if?(isEmpty(sourceStr)?||?expr?==?null)?{??
  1033. ????????????return?sourceStr;??
  1034. ????????}??
  1035. ????????if?(expr.length()?==?0)?{??
  1036. ????????????return?sourceStr;??
  1037. ????????}??
  1038. ????????int?pos?=?sourceStr.lastIndexOf(expr);??
  1039. ????????if?(pos?==?-1)?{??
  1040. ????????????return?sourceStr;??
  1041. ????????}??
  1042. ????????return?sourceStr.substring(0,?pos);??
  1043. ????}??
  1044. ???
  1045. ????/**?
  1046. ?????*?功能:截取出第一個標志位之后的字符串.<br/>?
  1047. ?????*?如果sourceStr為empty或者expr為null,直接返回源字符串。<br/>?
  1048. ?????*?如果expr長度為0,直接返回sourceStr。<br/>?
  1049. ?????*?如果expr在sourceStr中不存在,直接返回sourceStr。<br/>?
  1050. ?????*??
  1051. ?????*?@author?宋立君?
  1052. ?????*?@date?2014年06月24日?
  1053. ?????*?@param?sourceStr?
  1054. ?????*????????????被截取的字符串?
  1055. ?????*?@param?expr?
  1056. ?????*????????????分隔符?
  1057. ?????*?@return?String?
  1058. ?????*/??
  1059. ????public?static?String?substringAfter(String?sourceStr,?String?expr)?{??
  1060. ????????if?(isEmpty(sourceStr)?||?expr?==?null)?{??
  1061. ????????????return?sourceStr;??
  1062. ????????}??
  1063. ????????if?(expr.length()?==?0)?{??
  1064. ????????????return?sourceStr;??
  1065. ????????}??
  1066. ???
  1067. ????????int?pos?=?sourceStr.indexOf(expr);??
  1068. ????????if?(pos?==?-1)?{??
  1069. ????????????return?sourceStr;??
  1070. ????????}??
  1071. ????????return?sourceStr.substring(pos?+?expr.length());??
  1072. ????}??
  1073. ???
  1074. ????/**?
  1075. ?????*?功能:截取出第一個標志位之前的字符串.<br/>?
  1076. ?????*?如果sourceStr為empty或者expr為null,直接返回源字符串。<br/>?
  1077. ?????*?如果expr長度為0,直接返回sourceStr。<br/>?
  1078. ?????*?如果expr在sourceStr中不存在,直接返回sourceStr。<br/>?
  1079. ?????*?如果expr在sourceStr中存在不止一個,以第一個位置為準。?
  1080. ?????*??
  1081. ?????*?@author?宋立君?
  1082. ?????*?@date?2014年06月24日?
  1083. ?????*?@param?sourceStr?
  1084. ?????*????????????被截取的字符串?
  1085. ?????*?@param?expr?
  1086. ?????*????????????分隔符?
  1087. ?????*?@return?String?
  1088. ?????*/??
  1089. ????public?static?String?substringBefore(String?sourceStr,?String?expr)?{??
  1090. ????????if?(isEmpty(sourceStr)?||?expr?==?null)?{??
  1091. ????????????return?sourceStr;??
  1092. ????????}??
  1093. ????????if?(expr.length()?==?0)?{??
  1094. ????????????return?sourceStr;??
  1095. ????????}??
  1096. ????????int?pos?=?sourceStr.indexOf(expr);??
  1097. ????????if?(pos?==?-1)?{??
  1098. ????????????return?sourceStr;??
  1099. ????????}??
  1100. ????????return?sourceStr.substring(0,?pos);??
  1101. ????}??
  1102. ???
  1103. ????/**?
  1104. ?????*?功能:檢查這個字符串是不是空字符串。<br/>?
  1105. ?????*?如果這個字符串為null或者trim后為空字符串則返回true,否則返回false。?
  1106. ?????*??
  1107. ?????*?@author?宋立君?
  1108. ?????*?@date?2014年06月24日?
  1109. ?????*?@param?chkStr?
  1110. ?????*????????????被檢查的字符串?
  1111. ?????*?@return?boolean?
  1112. ?????*/??
  1113. ????public?static?boolean?isEmpty(String?chkStr)?{??
  1114. ????????if?(chkStr?==?null)?{??
  1115. ????????????return?true;??
  1116. ????????}?else?{??
  1117. ????????????return?"".equals(chkStr.trim())???true?:?false;??
  1118. ????????}??
  1119. ????}??
  1120. ???
  1121. ????/**?
  1122. ?????*?如果字符串沒有超過最長顯示長度返回原字符串,否則從開頭截取指定長度并加...返回。?
  1123. ?????*??
  1124. ?????*?@param?str?
  1125. ?????*????????????原字符串?
  1126. ?????*?@param?length?
  1127. ?????*????????????字符串最長顯示的長度?
  1128. ?????*?@return?轉換后的字符串?
  1129. ?????*/??
  1130. ????public?static?String?trimString(String?str,?int?length)?{??
  1131. ????????if?(str?==?null)?{??
  1132. ????????????return?"";??
  1133. ????????}?else?if?(str.length()?>?length)?{??
  1134. ????????????return?str.substring(0,?length?-?3)?+?"...";??
  1135. ????????}?else?{??
  1136. ????????????return?str;??
  1137. ????????}??
  1138. ????}??
  1139. ???
  1140. }??

二、MD5
[java] view plaincopyprint?在CODE上查看代碼片派生到我的代碼片
  1. package?com.mkyong.common;??
  2. ??
  3. import?java.io.File;??
  4. import?java.io.FileInputStream;??
  5. import?java.io.IOException;??
  6. import?java.nio.MappedByteBuffer;??
  7. import?java.nio.channels.FileChannel;??
  8. import?java.security.MessageDigest;??
  9. import?java.security.NoSuchAlgorithmException;??
  10. ??
  11. /**?
  12. ?*??
  13. ?*?String工具類.?<br>?
  14. ?*??
  15. ?*?@author?宋立君?
  16. ?*?@date?2014年06月24日?
  17. ?*/??
  18. public?class?MD5Util?{??
  19. ??
  20. ????protected?static?char?hexDigits[]?=?{?'0',?'1',?'2',?'3',?'4',?'5',?'6',??
  21. ????????????'7',?'8',?'9',?'a',?'b',?'c',?'d',?'e',?'f'?};??
  22. ??
  23. ????protected?static?MessageDigest?messagedigest?=?null;??
  24. ??
  25. ????static?{??
  26. ????????try?{??
  27. ????????????messagedigest?=?MessageDigest.getInstance("MD5");??
  28. ????????}?catch?(NoSuchAlgorithmException?nsaex)?{??
  29. ????????????System.err.println(MD5Util.class.getName()??
  30. ????????????????????+?"初始化失敗,MessageDigest不支持MD5Util。");??
  31. ????????????nsaex.printStackTrace();??
  32. ????????}??
  33. ????}??
  34. ??
  35. ????/**?
  36. ?????*?功能:加鹽版的MD5.返回格式為MD5(密碼+{鹽值})?
  37. ?????*??
  38. ?????*?@author?宋立君?
  39. ?????*?@date?2014年06月24日?
  40. ?????*?@param?password?
  41. ?????*????????????密碼?
  42. ?????*?@param?salt?
  43. ?????*????????????鹽值?
  44. ?????*?@return?String?
  45. ?????*/??
  46. ????public?static?String?getMD5StringWithSalt(String?password,?String?salt)?{??
  47. ????????if?(password?==?null)?{??
  48. ????????????throw?new?IllegalArgumentException("password不能為null");??
  49. ????????}??
  50. ????????if?(StringUtil.isEmpty(salt))?{??
  51. ????????????throw?new?IllegalArgumentException("salt不能為空");??
  52. ????????}??
  53. ????????if?((salt.toString().lastIndexOf("{")?!=?-1)??
  54. ????????????????||?(salt.toString().lastIndexOf("}")?!=?-1))?{??
  55. ????????????throw?new?IllegalArgumentException("salt中不能包含?{?或者?}");??
  56. ????????}??
  57. ????????return?getMD5String(password?+?"{"?+?salt.toString()?+?"}");??
  58. ????}??
  59. ??
  60. ????/**?
  61. ?????*?功能:得到文件的md5值。?
  62. ?????*??
  63. ?????*?@author?宋立君?
  64. ?????*?@date?2014年06月24日?
  65. ?????*?@param?file?
  66. ?????*????????????文件。?
  67. ?????*?@return?String?
  68. ?????*?@throws?IOException?
  69. ?????*?????????????讀取文件IO異常時。?
  70. ?????*/??
  71. ????public?static?String?getFileMD5String(File?file)?throws?IOException?{??
  72. ????????FileInputStream?in?=?new?FileInputStream(file);??
  73. ????????FileChannel?ch?=?in.getChannel();??
  74. ????????MappedByteBuffer?byteBuffer?=?ch.map(FileChannel.MapMode.READ_ONLY,?0,??
  75. ????????????????file.length());??
  76. ????????messagedigest.update(byteBuffer);??
  77. ????????return?bufferToHex(messagedigest.digest());??
  78. ????}??
  79. ??
  80. ????/**?
  81. ?????*?功能:得到一個字符串的MD5值。?
  82. ?????*??
  83. ?????*?@author?宋立君?
  84. ?????*?@date?2014年06月24日?
  85. ?????*?@param?str?
  86. ?????*????????????字符串?
  87. ?????*?@return?String?
  88. ?????*/??
  89. ????public?static?String?getMD5String(String?str)?{??
  90. ????????return?getMD5String(str.getBytes());??
  91. ????}??
  92. ??
  93. ????private?static?String?getMD5String(byte[]?bytes)?{??
  94. ????????messagedigest.update(bytes);??
  95. ????????return?bufferToHex(messagedigest.digest());??
  96. ????}??
  97. ??
  98. ????private?static?String?bufferToHex(byte?bytes[])?{??
  99. ????????return?bufferToHex(bytes,?0,?bytes.length);??
  100. ????}??
  101. ??
  102. ????private?static?String?bufferToHex(byte?bytes[],?int?m,?int?n)?{??
  103. ????????StringBuffer?stringbuffer?=?new?StringBuffer(2?*?n);??
  104. ????????int?k?=?m?+?n;??
  105. ????????for?(int?l?=?m;?l?<?k;?l++)?{??
  106. ????????????appendHexPair(bytes[l],?stringbuffer);??
  107. ????????}??
  108. ????????return?stringbuffer.toString();??
  109. ????}??
  110. ??
  111. ????private?static?void?appendHexPair(byte?bt,?StringBuffer?stringbuffer)?{??
  112. ????????char?c0?=?hexDigits[(bt?&?0xf0)?>>?4];??
  113. ????????char?c1?=?hexDigits[bt?&?0xf];??
  114. ????????stringbuffer.append(c0);??
  115. ????????stringbuffer.append(c1);??
  116. ????}??
  117. }??

三、File工具類
[java] view plaincopyprint?在CODE上查看代碼片派生到我的代碼片
  1. package?com.mkyong.common;??
  2. ??
  3. import?java.io.ByteArrayInputStream;??
  4. import?java.io.File;??
  5. import?java.io.FileInputStream;??
  6. import?java.io.FileOutputStream;??
  7. import?java.io.IOException;??
  8. import?java.io.InputStream;??
  9. import?java.io.OutputStream;??
  10. ??
  11. /**?
  12. ?*?文件相關操作輔助類。?
  13. ?*??
  14. ?*?@author?宋立君?
  15. ?*?@date?2014年06月24日?
  16. ?*/??
  17. public?class?FileUtil?{??
  18. ????private?static?final?String?FOLDER_SEPARATOR?=?"/";??
  19. ????private?static?final?char?EXTENSION_SEPARATOR?=?'.';??
  20. ??
  21. ????/**?
  22. ?????*?功能:復制文件或者文件夾。?
  23. ?????*??
  24. ?????*?@author?宋立君?
  25. ?????*?@date?2014年06月24日?
  26. ?????*?@param?inputFile?
  27. ?????*????????????源文件?
  28. ?????*?@param?outputFile?
  29. ?????*????????????目的文件?
  30. ?????*?@param?isOverWrite?
  31. ?????*????????????是否覆蓋(只針對文件)?
  32. ?????*?@throws?IOException?
  33. ?????*/??
  34. ????public?static?void?copy(File?inputFile,?File?outputFile,?boolean?isOverWrite)??
  35. ????????????throws?IOException?{??
  36. ????????if?(!inputFile.exists())?{??
  37. ????????????throw?new?RuntimeException(inputFile.getPath()?+?"源目錄不存在!");??
  38. ????????}??
  39. ????????copyPri(inputFile,?outputFile,?isOverWrite);??
  40. ????}??
  41. ??
  42. ????/**?
  43. ?????*?功能:為copy?做遞歸使用。?
  44. ?????*??
  45. ?????*?@author?宋立君?
  46. ?????*?@date?2014年06月24日?
  47. ?????*?@param?inputFile?
  48. ?????*?@param?outputFile?
  49. ?????*?@param?isOverWrite?
  50. ?????*?@throws?IOException?
  51. ?????*/??
  52. ????private?static?void?copyPri(File?inputFile,?File?outputFile,??
  53. ????????????boolean?isOverWrite)?throws?IOException?{??
  54. ????????//?是個文件。??
  55. ????????if?(inputFile.isFile())?{??
  56. ????????????copySimpleFile(inputFile,?outputFile,?isOverWrite);??
  57. ????????}?else?{??
  58. ????????????//?文件夾??
  59. ????????????if?(!outputFile.exists())?{??
  60. ????????????????outputFile.mkdir();??
  61. ????????????}??
  62. ????????????//?循環子文件夾??
  63. ????????????for?(File?child?:?inputFile.listFiles())?{??
  64. ????????????????copy(child,??
  65. ????????????????????????new?File(outputFile.getPath()?+?"/"?+?child.getName()),??
  66. ????????????????????????isOverWrite);??
  67. ????????????}??
  68. ????????}??
  69. ????}??
  70. ??
  71. ????/**?
  72. ?????*?功能:copy單個文件?
  73. ?????*??
  74. ?????*?@author?宋立君?
  75. ?????*?@date?2014年06月24日?
  76. ?????*?@param?inputFile?
  77. ?????*????????????源文件?
  78. ?????*?@param?outputFile?
  79. ?????*????????????目標文件?
  80. ?????*?@param?isOverWrite?
  81. ?????*????????????是否允許覆蓋?
  82. ?????*?@throws?IOException?
  83. ?????*/??
  84. ????private?static?void?copySimpleFile(File?inputFile,?File?outputFile,??
  85. ????????????boolean?isOverWrite)?throws?IOException?{??
  86. ????????//?目標文件已經存在??
  87. ????????if?(outputFile.exists())?{??
  88. ????????????if?(isOverWrite)?{??
  89. ????????????????if?(!outputFile.delete())?{??
  90. ????????????????????throw?new?RuntimeException(outputFile.getPath()?+?"無法覆蓋!");??
  91. ????????????????}??
  92. ????????????}?else?{??
  93. ????????????????//?不允許覆蓋??
  94. ????????????????return;??
  95. ????????????}??
  96. ????????}??
  97. ????????InputStream?in?=?new?FileInputStream(inputFile);??
  98. ????????OutputStream?out?=?new?FileOutputStream(outputFile);??
  99. ????????byte[]?buffer?=?new?byte[1024];??
  100. ????????int?read?=?0;??
  101. ????????while?((read?=?in.read(buffer))?!=?-1)?{??
  102. ????????????out.write(buffer,?0,?read);??
  103. ????????}??
  104. ????????in.close();??
  105. ????????out.close();??
  106. ????}??
  107. ??
  108. ????/**?
  109. ?????*?功能:刪除文件?
  110. ?????*??
  111. ?????*?@author?宋立君?
  112. ?????*?@date?2014年06月24日?
  113. ?????*?@param?file?
  114. ?????*????????????文件?
  115. ?????*/??
  116. ????public?static?void?delete(File?file)?{??
  117. ????????deleteFile(file);??
  118. ????}??
  119. ??
  120. ????/**?
  121. ?????*?功能:刪除文件,內部遞歸使用?
  122. ?????*??
  123. ?????*?@author?宋立君?
  124. ?????*?@date?2014年06月24日?
  125. ?????*?@param?file?
  126. ?????*????????????文件?
  127. ?????*?@return?boolean?true?刪除成功,false?刪除失敗。?
  128. ?????*/??
  129. ????private?static?void?deleteFile(File?file)?{??
  130. ????????if?(file?==?null?||?!file.exists())?{??
  131. ????????????return;??
  132. ????????}??
  133. ????????//?單文件??
  134. ????????if?(!file.isDirectory())?{??
  135. ????????????boolean?delFlag?=?file.delete();??
  136. ????????????if?(!delFlag)?{??
  137. ????????????????throw?new?RuntimeException(file.getPath()?+?"刪除失敗!");??
  138. ????????????}?else?{??
  139. ????????????????return;??
  140. ????????????}??
  141. ????????}??
  142. ????????//?刪除子目錄??
  143. ????????for?(File?child?:?file.listFiles())?{??
  144. ????????????deleteFile(child);??
  145. ????????}??
  146. ????????//?刪除自己??
  147. ????????file.delete();??
  148. ????}??
  149. ??
  150. ????/**?
  151. ?????*?從文件路徑中抽取文件的擴展名,?例如.?"mypath/myfile.txt"?->?"txt".?*?@author?宋立君?
  152. ?????*??
  153. ?????*?@date?2014年06月24日?
  154. ?????*?@param?文件路徑?
  155. ?????*?@return?如果path為null,直接返回null。?
  156. ?????*/??
  157. ????public?static?String?getFilenameExtension(String?path)?{??
  158. ????????if?(path?==?null)?{??
  159. ????????????return?null;??
  160. ????????}??
  161. ????????int?extIndex?=?path.lastIndexOf(EXTENSION_SEPARATOR);??
  162. ????????if?(extIndex?==?-1)?{??
  163. ????????????return?null;??
  164. ????????}??
  165. ????????int?folderIndex?=?path.lastIndexOf(FOLDER_SEPARATOR);??
  166. ????????if?(folderIndex?>?extIndex)?{??
  167. ????????????return?null;??
  168. ????????}??
  169. ????????return?path.substring(extIndex?+?1);??
  170. ????}??
  171. ??
  172. ????/**?
  173. ?????*?從文件路徑中抽取文件名,?例如:?"mypath/myfile.txt"?->?"myfile.txt"。?*?@author?宋立君?
  174. ?????*??
  175. ?????*?@date?2014年06月24日?
  176. ?????*?@param?path?
  177. ?????*????????????文件路徑。?
  178. ?????*?@return?抽取出來的文件名,?如果path為null,直接返回null。?
  179. ?????*/??
  180. ????public?static?String?getFilename(String?path)?{??
  181. ????????if?(path?==?null)?{??
  182. ????????????return?null;??
  183. ????????}??
  184. ????????int?separatorIndex?=?path.lastIndexOf(FOLDER_SEPARATOR);??
  185. ????????return?(separatorIndex?!=?-1???path.substring(separatorIndex?+?1)??
  186. ????????????????:?path);??
  187. ????}??
  188. ??
  189. ????/**?
  190. ?????*?功能:保存文件。?
  191. ?????*??
  192. ?????*?@author?宋立君?
  193. ?????*?@date?2014年06月24日?
  194. ?????*?@param?content?
  195. ?????*????????????字節?
  196. ?????*?@param?file?
  197. ?????*????????????保存到的文件?
  198. ?????*?@throws?IOException?
  199. ?????*/??
  200. ????public?static?void?save(byte[]?content,?File?file)?throws?IOException?{??
  201. ????????if?(file?==?null)?{??
  202. ????????????throw?new?RuntimeException("保存文件不能為空");??
  203. ????????}??
  204. ????????if?(content?==?null)?{??
  205. ????????????throw?new?RuntimeException("文件流不能為空");??
  206. ????????}??
  207. ????????InputStream?is?=?new?ByteArrayInputStream(content);??
  208. ????????save(is,?file);??
  209. ????}??
  210. ??
  211. ????/**?
  212. ?????*?功能:保存文件?
  213. ?????*??
  214. ?????*?@author?宋立君?
  215. ?????*?@date?2014年06月24日?
  216. ?????*?@param?streamIn?
  217. ?????*????????????文件流?
  218. ?????*?@param?file?
  219. ?????*????????????保存到的文件?
  220. ?????*?@throws?IOException?
  221. ?????*/??
  222. ????public?static?void?save(InputStream?streamIn,?File?file)?throws?IOException?{??
  223. ????????if?(file?==?null)?{??
  224. ????????????throw?new?RuntimeException("保存文件不能為空");??
  225. ????????}??
  226. ????????if?(streamIn?==?null)?{??
  227. ????????????throw?new?RuntimeException("文件流不能為空");??
  228. ????????}??
  229. ????????//?輸出流??
  230. ????????OutputStream?streamOut?=?null;??
  231. ????????//?文件夾不存在就創建。??
  232. ????????if?(!file.getParentFile().exists())?{??
  233. ????????????file.getParentFile().mkdirs();??
  234. ????????}??
  235. ????????streamOut?=?new?FileOutputStream(file);??
  236. ????????int?bytesRead?=?0;??
  237. ????????byte[]?buffer?=?new?byte[8192];??
  238. ????????while?((bytesRead?=?streamIn.read(buffer,?0,?8192))?!=?-1)?{??
  239. ????????????streamOut.write(buffer,?0,?bytesRead);??
  240. ????????}??
  241. ????????streamOut.close();??
  242. ????????streamIn.close();??
  243. ????}??
  244. }??

轉載于:https://www.cnblogs.com/archermeng/p/7537612.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/374391.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/374391.shtml
英文地址,請注明出處:http://en.pswp.cn/news/374391.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Oracle定時器調用存儲過程

關于Oracle定時器調用存儲過程的一點總結&#xff0c;如果有不足的地方&#xff0c;希望大家多多指導&#xff0c;也是第一次在博客上寫東西&#xff0c;以前也只是自己總結之后放在硬盤了&#xff0c;后來同事告訴自己&#xff0c;其實寫博客可以獲得很多&#xff0c;不管是知…

python可以下載百度文庫_不用下載券也能下載百度文庫資料,Python幫你輕松搞定...

大家可能平時都有在百度文庫下載文檔的經歷&#xff0c;費盡心思好不容易在文庫找了一份可以用的資料&#xff0c;一看需要用下載券下載&#xff0c;搞的人很煩。 有的人為了節省時間&#xff0c;就任性辦理了個文庫VIP&#xff0c;再也不用糾結怎么下文檔了。如果你是一個百度…

將對象映射到多個XML模式–天氣示例

我已經在EclipseLink JAXB&#xff08;MOXy&#xff09;的XmlPath和外部綁定文件擴展中撰寫了以前的文章。 在本文中&#xff0c;我將通過將單個對象模型映射到兩個不同的XML模式來演示這些擴展的功能。 為了使示例更加“真實”&#xff0c;XML數據將來自提供天氣信息的兩種不同…

STM32F1筆記(九)通用定時器

STM32F1的定時器分為TIME1/8等高級定時器&#xff0c;TIME2~5等通用定時器&#xff0c;TIME6/7基本定時器。三者的區別主要參考《STM32中文參考手冊》里特性的每種定時器主要特性的異同。 先看中文手冊中通用定時器的簡介&#xff1a; 通用定時器的寄存器有一個比較有趣的地方…

佳能MP258的5200錯誤和P08代碼解決方法及清零方法

參考文章轉載于:https://www.cnblogs.com/arcer/p/5659624.html

tomcat通過conf-Catalina-localhost目錄發布項目詳解

轉自&#xff1a;http://www.cnblogs.com/iyangyuan/p/3316444.html&#xff0c;感謝 楊元。 Tomcat發布項目的方式大致有三種&#xff0c;但小菜認為通過在tomcat的conf/Catalina/localhost目錄下添加配置文件&#xff0c;來發布項目&#xff0c;是最佳選擇。 因為這樣對tomca…

c++保存圖標到dll_自動保存郵件附件至指定文件夾

最近有個需求&#xff0c;ERP系統會自動發很多csv附件到我郵箱&#xff0c;我需要把這些附件上傳到FTP服務器&#xff0c;服務器會把這些csv的數據寫到另外一個系統的數據庫。每次大概有30個郵件&#xff0c;每個郵件有一個附件&#xff0c;而且附件的名字都一樣&#xff0c;是…

有時在Java中,一個布局管理器是不夠的

在開發Java Swing應用程序時&#xff0c;最經常的是&#xff0c;我們需要在多個嵌套面板中使用多個布局管理器。 通常這不是問題&#xff0c;并且被認為是幾乎所有人類已知語言的所有UI開發的常規做法。 但是&#xff0c;大多數情況下&#xff0c;對于UI中的每個面板&#xff0…

VM克隆之后啟動eth0找不到eth0:unknown interface:no such device

問題出現&#xff1a;VMware 克隆之后&#xff0c;ifconfig命令執行找不到eth0,報錯 eth0:unknown interface:no such device 是因為/etc/sysconf/network-scripts/ifcfg-eth0配置復制過來和虛擬主機的網卡Mac等信息不匹配 解決方法&#xff1b; 刪除/etc/udev/rules.d/70-pers…

“精彩極了”和“糟糕透了”

雖然已經是25歲&#xff0c;但是對小學的一篇課文依然記憶尤新&#xff0c;《“精彩極了”和“糟糕透了”》。 課文正文 記得七八歲的時候&#xff0c;我寫了第一首詩。母親一念完那首詩&#xff0c;眼睛亮亮的&#xff0c;興奮地嚷著&#xff1a;“巴迪&#xff0c;真是你寫的…

python中print的用法_Python中print函數簡單使用總結

Python中print函數簡單使用總結 print函數是Python的入門&#xff0c;每一個學習python的人都繞不開這個函數&#xff0c;下面介紹一下這個函數的用法。 打開電腦&#xff0c;選擇python軟件&#xff0c;下面選擇python 3.7為例進行介紹&#xff0c;點擊python 3.7&#xff0c;…

STM32F1筆記(十)PWM

PWM&#xff1a;Pulse Width Modulation&#xff0c;脈沖寬度調制。是利用微處理器的數字輸出來對模擬電路進行控制的一種非常有效的技術。簡單來說就是對脈沖寬度的控制。 在《STM32中文參考手冊》里可以看到 占空比&#xff1a;占空比是指在一個脈沖循環內&#xff0c;通電時…

從GlassFish 3.x擴展到WebLogic 12c Server

Oracle針對GlassFish服務器的策略的主要目標之一是“與Fusion Middleware and Products集成”&#xff08;來源&#xff1a; Community Roadmap&#xff0c;2010年5月 &#xff09;。 在今年早些時候&#xff0c;您聽到了很多關于兩臺服務器合而為一的恐懼和謠言。 看到這兩種產…

移動互聯網時代:如何讓女孩愛上你在一分鐘內?

部分《移動互聯網時代&#xff1a;讓女孩愛上你在一分鐘內》其實我只是做原來的盲目思想有移動互聯網的自主知識產權&#xff0c;他沒有詳細說明如何真正讓女孩愛上你在一分鐘內&#xff1f;在真實生活中&#xff0c;預期也沒有那么簡單&#xff0c;易于&#xff0c;畢竟&#…

hashset去重原理_基于simhash的文本去重原理

互聯網網頁存在著大量重復內容&#xff0c;必須有一套高效的去重算法&#xff0c;否則爬蟲將做非常多的無用功&#xff0c;工作時效性無法得到保證&#xff0c;更重要的是用戶體驗也不好。業界關于文本指紋去重的算法眾多&#xff0c;如 k-shingle 算法、google 提出的simhash …

解決express video 手機無法播放的問題

http://stackoverflow.com/questions/24976123/streaming-a-video-file-to-an-html5-video-player-with-node-js-so-that-the-video-c 項目地址 https://github.com/shenggen1987/mp4-demo express index.jade extends layoutblock contenth1 titlep Welcome to #{title}vid…

STM32F1筆記(十一)ADC

查看《STM32中文參考手冊》里ADC的介紹和特性 STM32的ADC最大轉換速率為1Mhz&#xff0c;即1us&#xff0c;在ADCCLK14M&#xff0c;采樣周期為1.5個ADC時鐘下得到。當ADC的時鐘超過14M時&#xff0c;將導致結果準確度下降。 規則通道相當于正常運行的程序。注入通道就相當于中…

使用JPA和Spring 3.1進行事務配置

1.概述 本教程將討論配置Spring Transactions &#xff0c;使用Transactional批注和常見陷阱的正確方法 。 要更深入地討論核心持久性配置&#xff0c;請查看Spring with JPA教程 。 有兩種不同的配置事務的方法– 批注和AOP –每種都有自己的優勢–我們將在這里討論更常見的…

java epoll select_字節跳動高頻面試題,操作系統/算法/Java等。

字節跳動# Java▲ 20 Java 中垃圾回收機制中如何判斷對象需要回收&#xff1f;常見的 GC 回收算法有哪些&#xff1f;▲ 18 synchronized 關鍵字底層是如何實現的&#xff1f;它與 Lock 相比優缺點分別是什么&#xff1f;▲ 17 hashmap 和 hashtable 的區別是什么&#xff1f;▲…

Xamarin Android項目運行失敗

Xamarin Android項目運行失敗 錯誤信息&#xff1a;Build Failed: MonoDroid does not support running the previous version. Please ensure your solution builds before running or debugging it.這是由于由于項目生成失敗&#xff0c;并找不到以前編譯的結果。這時&#…