(数据流)DataInputStreamAndOut

    xiaoxiao2021-03-25  98

    /** * 输出的数据流   相当于一次加密 */ public static void testData(){ DataOutputStream dos = null; try { dos = new DataOutputStream(new FileOutputStream(new File("data.txt"))); dos.writeUTF("我爱你,而你却不知道!"); dos.writeBoolean(true); dos.writeLong(15371247239L); }  catch (IOException e) { e.printStackTrace(); }finally { if(dos != null){ try { dos.close(); } catch (IOException e) { e.printStackTrace(); } } }

    }

    /** * 输入的数据流   相当于解密 */ public static void testData1(){ DataInputStream dis = null; try { dis = new DataInputStream(new FileInputStream(new File("data.txt"))); String str = dis.readUTF(); System.out.println(str); boolean b = dis.readBoolean(); System.out.println(b); long l = dis.readLong(); System.out.println(l); }  catch (IOException e) { e.printStackTrace(); }finally { if(dis != null){ try { dis.close(); } catch (IOException e) { e.printStackTrace(); } } } }

    转载请注明原文地址: https://ju.6miu.com/read-24253.html

    最新回复(0)