I want to write byte array to txt file. Firstly I want to see that data in eclipse console and I see that data are true. But when I want to write this data into txt file the problem is manifest itself. Txt file is coming with errors.
My code is as follows.
FileOutputStream fos;
try {
fos = new FileOutputStream("/usr/text110.txt");
fos.write(imageInByte);
fos.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
My txt file is as follows. How can I save my byte array to file properly. Please help me.
\00-0R~\9D\B6\C9\D9\DD\EB\F1\FA\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FA\EF\EF\E4\E0\E2\DA\D9\D7\D0\CE\C4\C1\C0\B6\B5\B1\AE\B0\A1\A2\A0\99\9D\99\95\98\92\95\93\8E\92\91\95\85\86\86\86\8A\8A\89\8C\88\8C\84\81\80y}~{||||zzxxwzyusoklnppjqy\81\8E\8F\94\91\97\99\A0\B2\C4\D2\E0\E9\EA\E7\EC\E9\E9\E7\E3\E3\D9\DC\D3\CF\D0\C7\C7\C6\C2ü\BD\B4\B1\AC\A1\A0\9E\97\96\8E\84\84\83\88\85\89znlx{\86\86\8C\90\8D\92\90\90\94\90\95\91\94\92\90\91\89\8B\84\83ungiba[X\cbfbc^SRSSXUKILTVbes|\8C\95\9D\AA\B4\B6\B4\C5\D2\E3\EC\F2\FA\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\FF\F4\E8\E0\DE\D9\D2\D8\D6\D4\CC\CB\C8\C6\C5\C9ļ\BC\BF\BE\C1\BC\C0\BE\C0\BD\BC\BE\B9\B7\AE\A8\A8\A7\A5\AA\A8\AE\AD\B2\B2\B1\B5\B0\B2\AD\AF\AC\A8\A8\A2\A5\A1\9F\97\8D\8D\91\94\9C\9C\A3\A2\A7\A4\A3\A1\9C\9E\9B\9A\9E\9A\9C\96\8D\8B\90\99\A2\A3\A5\A6\AA\AC\B2\B9\BC\BE\C3\C2\C6\C1¿\B9\BD\B8\BD\B9\BB\B3\AB\97\9A\9A\A1\A0\A5\A2\A4\A2\9F\9E\96\98\91\90\89\82\81\81\83\83\86\86\82\80vwtyx}}\80\82\83\85\84\86\83\85}\80\80\83~\82}|}|{\80}\82\81\87\86\8B\89\8B\86\85\80xsyy|\80trrv\83\86\93\9F\A5\B1\AC\AE\B6\BC\BF\C9\C9\C9\C9\CD\D6\D4\CF\CD\D8\DB\E4\E2\E8\E9\E8\ED\E9\EF\EA\EE\ED\E8\EA\E2\E4\E2\DE\E0\D9\DB\D2\D3\CB\C9ķ\AA\9A\9B\96\98\9F\9F\A6\A3\A7\A0\A2\99\8D\85\8B\8B\90\8E\93\92\90\93\8F\91\8E\91\8F\90\8A\8A\82\84\80\82\81\81zwla_dmqzy\81~\83\86\82\88\85\86\8A\85\86~zz\81\83\86\80t|}u{\85\85\8F\8E\93\9A\9A\A0\9C\93\8D\93\92\99\93\97\99\93\99\96\9A\9A\95\96\91\89\8D\89\8D\8B\8A\8D\85\89\88\85\8A\84\88\82\82yuqgb^UUQQQJJC?1217387>\bjiowrv~\81\80\88\8C\8A\92\95\92\99\9C\99\9F\A1\9D\A3\A1\A2\A7\A1\A5\A9\A4\A9\AB\A6\AC\AA\AC\B1\AB\B0\B1\AB\B0\AA\AB\AF\A9\AC\AB\A9\AD\A6\A9\A6\A5\A7\9F\A1\A0\9B\9E\96\98\97\91\92\89\8B\87\83\83yzqonfibcaZVJ=.)##!#)($'% -8:FMOX]Yagcjohmqknphlkejiflhjnijmdegadbc_b_VZ]VXRHGAEBLKRSRVQSNQQMNEGIDIDJLJOGJEA=5-))*.+.''..16.*3;:EIKTYU_fbjrou|y|\83\80\82\88\84\85\8B\86\88\8C\86\8A\8E\88\8D\8F\8A\90\90\8E\92\8E\90\94\8E\91\93\8C\90\90\8D\90\89\8C\8C\85\89\82\82\85~\82\80\83~\82\81\82{}|vyqrmih^^TTJF:45.5226.1-0.+.'"!'+4<9BJGMTPT[[V]_X_VYZUYUTYQU[UZ_Y]aZ\^UWTNOFIMIMQLPOCD?96'!(+15/4/1+-'#!! &%),)( #!',(185=D?ENNPY[Xafahnhotorwquyruyrwysyyu|xz~y|\80z~\80z~~{~wz|twvswqutquprtnrplpimlgiacc\^TVTQRGJH@@550*)!& " "$+-687>C?FLFKRPPUUMQQJLGGICHJFLPKQUNSVMQRJMKHJADHAFIDGHAC?9:68369/35110..))#" " #-/,5<8@FAGOKOVYV]\ae^be^bd^ab[]]b]faeidgkdhjchhbfac_`X\VWYRWWTXRVXQURQUMPPIMFHIFGA<:>8;CEAGH?CC:<53626638748647340+.-/#),'+)(!# !
")&'0229>;BGAGMIKQRNSUPTVORQLOIJNIMQHNRLRVPUXPTVPTTPTQOQGJLBE??B;@A@FAAE?BC;?9=@9<96:311*.''(! %!$'!'-05029:59<458200+%!#(&-4/5;439:8:70/(+("'#&,(+)(*! "!"#%$!
$#)#&.-,4:8>C=@E@=BB=AB>>:992686A?=@57911+("))/)&&.*+&&(!&%%#!"#"#
解决方案
FileOutputStream fos = FileOutputStream("path/to/the/file/to/write/in");
fos.write(theByteArray);
fos.close();
Will write the byte array in byte form.
FileOutputStream fos = FileOutputStream("path/to/the/file/to/write/in");
for (byte b : bytes) {
fos.write(String.format("%02X ", b).getBytes());
}
fos.write(theByteArray);
fos.close();
Will write byte array in human readable form.