lernen.2007
Erfahrenes Mitglied
Ich habe in google viel nachgeschaut aber nichts sinnvolles gefunden. Was heisst Objekt lesen und schreiben in/aus Datei.Was kann man damit machen.
Danke
erkan
Danke
erkan
Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
public void writeExternal(ObjectOutput out) throws IOException {
// TODO Auto-generated method stub
}
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
// TODO Auto-generated method stub
}
/**
*
*/
package de.tutorials;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
/**
* @author Tom
*
*/
public class SerializationExample {
/**
* @param args
*/
public static void main(String[] args) throws Exception{
BusinessObject businessObject = new BusinessObject(4711L,"someData","secret");
System.out.println(businessObject);
File file = new File("c:/businessObject.ser");
ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream(file));
objectOutputStream.writeObject(businessObject);
objectOutputStream.close();
ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream(file));
BusinessObject businessObject2 = (BusinessObject)objectInputStream.readObject();
objectInputStream.close();
System.out.println(businessObject2);
}
static public class BusinessObject implements Serializable {
long id;
final String FOO;
transient String secret;
String data;
public BusinessObject(long id, String data,String secret) {
this.id = id;
this.data = data;
this.FOO = "ABC";
this.secret = secret;
}
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
public String getFOO() {
return FOO;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getSecret() {
return secret;
}
public void setSecret(String secret) {
this.secret = secret;
}
public String toString() {
StringBuffer buffer = new StringBuffer(30);
buffer.append(super.toString());
buffer.append(",id=");
buffer.append(id);
buffer.append(",FOO=");
buffer.append(FOO);
buffer.append(",secret=");
buffer.append(secret);
buffer.append(",data=");
buffer.append(data);
return buffer.toString();
}
}
}