Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- *
- * @author Shreya Dhaga
- */
- import java.io.*;
- import java.util.Scanner;
- class Details {
- Scanner scan = new Scanner(System.in);
- String username = new String();
- String password = new String();
- void getName() {
- System.out.println("Take username");
- this.username = scan.next();
- }
- String setName() {
- return this.username;
- }
- void getPassword() {
- System.out.println("Take password");
- this.password = scan.next();
- }
- String setPassword() {
- return this.password;
- }
- }
- public class ObjectOutputStreamDemo {
- public static void main(String[] args) {
- Details g = new Details();
- String s, q;
- //TODO run this for multiple times
- g.getName();
- g.getPassword();
- s = g.setName();
- q = g.setPassword();
- try {
- FileOutputStream out = new FileOutputStream("F:\\newfile.txt");
- ObjectOutputStream login = new ObjectOutputStream(out);
- login.writeObject(s);
- login.writeObject(q);
- login.close();
- // check that the file is appended in multiple run
- // TODO search a string in a file
- // character wise check or string cmp
- FileInputStream in = new FileInputStream("F:\\newfile.txt");
- ObjectInputStream iin = new ObjectInputStream(in);
- System.out.println("" + (String) iin.readObject() + " " + (String) iin.readObject());
- } catch (Exception e) {
- System.out.println("Exception caught");
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement