IOsample - String message = dis.readUTF read/receive...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
CodeSamples
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background image of page 2
CodeSamples Reading from the keyboard BufferedReader br = new BufferedReader( new InputStreamReader(System.in)); String input = br.readLine(); // wait for ENTER key Reading text data from a disk file BufferedReader br = new BufferedReader( new FileReader("data_in.txt")); String input = br.readLine(); // Read up to new line character Writing text data to a disk file BufferedWriter bw = new BufferedWriter( new FileWriter("data_out.txt",true)); // append mode br.write("This is a new entry to the log."); // add a line to the file br.newLine(); // write a new line character Sending/receiving messages over a communications line Socket s = new Socket("HostAddress", hostPort); // String, int DataInputStream dis = new DataInputStream (s.getInputStream()); DataOutputStream dos = new DataOutputStream(s.getOutputStream());
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Background image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: String message = dis.readUTF(); // read/receive dos.writeUTF("Do you have Grey Poupon?"); // write/send Sending/receiving Java objects over the network ObjectInputStream ois = new ObjectInputStream (dis); // see dis above ObjectOutputStream oos = new ObjectOutputStream(dos); // see dos above Object o = ois.readObject(); oos.writeObject(studentData); Saving/restoring objects to/from disk ObjectOutputStream oos = new ObjectOutputStream( new FileOutputStream("student_data.ser")); ObjectInputStream ois = new ObjectInputStream( new FileInputStream ("student_data.ser")); oos.writeObject(studentData); // save object on disk StudentData sd = ois.readObject(); // restore Object From Disk...
View Full Document

{[ snackBarMessage ]}

Page1 / 4

IOsample - String message = dis.readUTF read/receive...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online