Example usage for java.io ObjectOutputStream close

List of usage examples for java.io ObjectOutputStream close

Introduction

In this page you can find the example usage for java.io ObjectOutputStream close.

Prototype

public void close() throws IOException 

Source Link

Document

Closes the stream.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {

    String s = "Hello World from java2s.com";

    FileOutputStream out = new FileOutputStream("test.txt");
    ObjectOutputStream oout = new ObjectOutputStream(out);

    oout.writeObject(s);// w  w  w.  ja  v  a2  s.com
    oout.flush();
    oout.close();
    Main ois = new Main(new FileInputStream("test.txt"));

    System.out.println((String) ois.readObjectOverride());
    ois.close();
}

From source file:Main.java

public static void main(String[] args) {
    Card card = new Card();
    try {//from w w w .  ja v a2s. co  m
        FileOutputStream out = new FileOutputStream("card.out");
        ObjectOutputStream oos = new ObjectOutputStream(out);
        oos.writeObject(card);
        oos.flush();
        oos.close();
    } catch (Exception e) {
        System.out.println("Problem serializing: " + e);
    }
}

From source file:Main.java

public static void main(String args[]) throws Exception {
    ServerSocket ssock = new ServerSocket(1234);
    Hashtable hash = new Hashtable();
    hash.put("A", "a");

    while (true) {
        Socket sock = ssock.accept();
        ObjectOutputStream ostream = new ObjectOutputStream(sock.getOutputStream());
        ostream.writeObject(hash);//  w ww .  jav  a 2  s. co  m
        ostream.close();
        sock.close();
    }
}

From source file:ObjectWriter.java

public static void main(String[] arguments) {
    Message mess = new Message();
    String author = "London";
    String recipient = "G, B";
    String[] letter = { "Merry Christmas." };
    Date now = new Date();
    mess.writeMessage(author, recipient, now, letter);
    try {/*from   www . ja va  2s . com*/
        FileOutputStream fo = new FileOutputStream("Message.obj");
        ObjectOutputStream oo = new ObjectOutputStream(fo);
        oo.writeObject(mess);
        oo.close();
        System.out.println("Object created successfully.");
    } catch (IOException e) {
        System.out.println("Error - " + e.toString());
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {

    String s = "Hello World from java2s.com";

    FileOutputStream out = new FileOutputStream("test.txt");
    ObjectOutputStream oout = new ObjectOutputStream(out);

    oout.writeUTF(s);/*from w w w  . ja  va 2 s  .c  om*/
    oout.flush();
    oout.close();

    Main ois = new Main(new FileInputStream("test.txt"));

    String[] list = { Serializable.class.getName() };

    System.out.println(ois.resolveProxyClass(list));
    ois.close();
}

From source file:MainClass.java

public static void main(String[] args) {
    Employee e = new Employee();
    e.name = "Jor Lee";
    e.address = "USA";
    e.SSN = 11122333;/*from   ww  w.  j a v  a2s  . c  o  m*/
    e.number = 101;

    try {
        FileOutputStream fileOut = new FileOutputStream("employee.ser");
        ObjectOutputStream out = new ObjectOutputStream(fileOut);

        out.writeObject(e);

        out.close();
        fileOut.close();
    } catch (IOException i) {
        i.printStackTrace();
    }
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    User a = new User("A", "B");
    System.out.println("logon a = " + a);
    ObjectOutputStream o = new ObjectOutputStream(new FileOutputStream("User.out"));
    o.writeObject(a);/* w  ww.  ja va2 s. c  o  m*/
    o.close();

    Thread.sleep(1000); // Delay for 1 second

    ObjectInputStream in = new ObjectInputStream(new FileInputStream("User.out"));
    System.out.println("Recovering object at " + new Date());
    a = (User) in.readObject();
    System.out.println("logon a = " + a);
}

From source file:EmployeeInit.java

public static void main(String[] args) throws Exception {
    Connection con;/*from   ww w . j  a  v a 2  s  .  c o m*/
    con = DriverManager.getConnection("jdbc:derby://localhost:1527/" + "c:\\db\\employee");

    PreparedStatement ps;
    ps = con.prepareStatement("insert into employee(name,photo) " + "values(?,?)");
    ps.setString(1, "Duke");

    Blob blob = con.createBlob();
    ImageIcon ii = new ImageIcon("duke.png");

    ObjectOutputStream oos;
    oos = new ObjectOutputStream(blob.setBinaryStream(1));
    oos.writeObject(ii);
    oos.close();
    ps.setBlob(2, blob);
    ps.execute();
    blob.free();
    ps.close();
}

From source file:CachedRS.java

public static void main(String[] args) throws Exception {
    FileInputStream fis = new FileInputStream(CRS_FILE_LOC);
    ObjectInputStream in = new ObjectInputStream(fis);
    CachedRowSet crs = (CachedRowSet) in.readObject();
    fis.close();//from   w w w . ja  v a2s. c  om
    in.close();

    Class.forName("oracle.jdbc.driver.OracleDriver");
    crs.setUrl("jdbc:oracle:thin:@localhost:1521:ORCL");
    crs.setUsername("yourName");
    crs.setPassword("mypwd");
    String sql = "SELECT SSN, Name, Salary, Hiredate FROM Employees WHERE SSN=?";
    crs.setCommand(sql);
    crs.setInt(1, 111111111);
    crs.execute();

    FileOutputStream fos = new FileOutputStream(CRS_FILE_LOC);
    ObjectOutputStream out = new ObjectOutputStream(fos);
    out.writeObject(crs);
    out.close();
    crs.close();

    fis = new FileInputStream(CRS_FILE_LOC);
    in = new ObjectInputStream(fis);
    crs = (CachedRowSet) in.readObject();
    fis.close();
    in.close();

    while (crs.next()) {
        System.out.print("SSN: " + crs.getInt("ssn"));
        System.out.print(", Name: " + crs.getString("name"));
        System.out.print(", Salary: $" + crs.getDouble("salary"));
        System.out.print(", HireDate: " + crs.getDate("hiredate"));
    }
    crs.close();
}

From source file:Employee.java

public static void main(String[] args) {
    Employee e = new Employee();
    e.name = "A";
    e.address = "B";
    e.SSN = 11111;//w  w w.jav a 2  s. com
    e.number = 101;
    try {
        FileOutputStream fileOut = new FileOutputStream("employee.ser");
        ObjectOutputStream out = new ObjectOutputStream(fileOut);
        out.writeObject(e);
        out.close();
        fileOut.close();
    } catch (IOException i) {
        i.printStackTrace();
    }
}