浏览 1479 次
锁定老帖子 主题:请教加密代码原理
该帖已经被评为新手帖
|
|
---|---|
作者 | 正文 |
发表时间:2008-02-21
public class WriteBin { public static void main(String[] str) { readTest(); for(int i=0; i<=3;i++){ System.out.println("nDrawPos=" + nDrawPos[i]); nDrawPos[i]=jiami(nDrawPos[i]); System.out.println("after=" + nDrawPos[i]); } writenDrawPos("c:/miglove.bin"); } static String nDrawPos[]; //---------------------------------------------------------------------------- public static String jiami(String s){ String ss = ""; byte[] b = s.getBytes(); for(int i=0; i<b.length;i++){ b[i] = (byte)(b[i] + 7); } return new String(b); } //----------------------------------------------------------------------------读 public static void readTest() { try { DataInputStream is = new DataInputStream(new FileInputStream("c:/test.txt")); nDrawPos = new String[19]; readLine(is); for (int i = 0; i < nDrawPos.length; i++) { nDrawPos[i] = readLine(is); } is.close(); is = null; } catch (Exception ex) {} } public static String readLine(InputStream is) throws IOException { try { byte[] data; String str; int b; ByteArrayOutputStream baos; baos = new ByteArrayOutputStream(); b = 0; while ( (b = is.read()) != -1) { if (b == 10) { break; } if (b != 13) { baos.write(b); } } baos.close(); data = baos.toByteArray(); if (data.length > 0) { str = convertFromUTF8(data); } else if (b != -1) { str = null; } else { str = ""; } baos = null; return str; } catch (Exception e) { return "x"; } } public static String convertFromUTF8(byte[] data) { if (data == null) { return null; } try { int len = data.length; byte[] newdata = new byte[len + 2]; newdata[0] = (byte) (len >>>; newdata[1] = (byte) len; System.arraycopy(data, 0, newdata, 2, len); ByteArrayInputStream bis = new ByteArrayInputStream(newdata); DataInputStream dis = new DataInputStream(bis); return dis.readUTF(); } catch (Exception e) { // System.out.println(e + " Bad UTF8 string"); return null; } } //----------------------------------------------------------------------------写 private static void writenDrawPos(String fileName) { try { DataOutputStream dos = new DataOutputStream(new FileOutputStream(fileName)); dos.writeShort(nDrawPos.length); for (int i = 0; i < nDrawPos.length; i++) { String temp = nDrawPos[i]; dos.writeUTF(temp); } dos.flush(); dos.close(); } catch (Exception ex) {} } } 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |