Example10_11.java
import java.io.*; public class Example10_11 { public static void main(String args[]) { File file=new File("apple.txt"); try{ FileOutputStream fos=new FileOutputStream(file); DataOutputStream outData=new DataOutputStream(fos); outData.writeInt(100); outData.writeLong(123456); outData.writeFloat(3.1415926f); outData.writeDouble(987654321.1234); outData.writeBoolean(true); outData.writeChars("How are you doing "); } catch(IOException e){} try{ FileInputStream fis=new FileInputStream(file); DataInputStream inData=new DataInputStream(fis); System.out.println(inData.readInt()); //读取int数据 System.out.println(inData.readLong()); //读取long数据 System.out.println(+inData.readFloat()); //读取float数据 System.out.println(inData.readDouble()); //读取double数据 System.out.println(inData.readBoolean());//读取boolean数据 char c = '\0'; while((c=inData.readChar())!='\0') { //'\0'表示空字符。 System.out.print(c); } } catch(IOException e){} } }
Example10_12.java
import java.io.*; public class Example10_12 { public static void main(String args[]) { String command = "渡江总攻时间是4月22日晚10点"; EncryptAndDecrypt person = new EncryptAndDecrypt(); String password = "Tiger"; String secret = person.encrypt(command,password); File file=new File("secret.txt"); try{ FileOutputStream fos=new FileOutputStream(file); DataOutputStream outData=new DataOutputStream(fos); outData.writeUTF(secret); System.out.println("加密命令:"+secret); } catch(IOException e){} try{ FileInputStream fis=new FileInputStream(file); DataInputStream inData=new DataInputStream(fis); String str = inData.readUTF(); String mingwen = person.decrypt(str,password); System.out.println("解密命令:"+mingwen); } catch(IOException e){} } }标签:java,String,inData,System,outData,数据流,new,out From: https://www.cnblogs.com/kn-zheng/p/17147678.html