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.
import java.util.LinkedList;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.ObjectInputStream;
import java.io.FileOutputStream;
import java.io.FileInputStream;
class LinkListSerializer{
public static void serializeListToFile(LinkedList<Integer> list, String file){
try{
ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream(file));
os.writeObject(list);
os.close();
}
catch(IOException e){
System.out.println("IOException occured :(");
e.printStackTrace();
}
}
public static LinkedList<Integer> deserializeListFromFile(String file){
LinkedList<Integer> ret = null;
try{
ObjectInputStream is = new ObjectInputStream(new FileInputStream(file));
ret = (LinkedList<Integer>)(is.readObject());
is.close();
}
catch(Exception e){
System.out.println("IOException occured :(");
e.printStackTrace();
}
return ret;
}
public static void main(String[] args){
String file = "linkedlist.obj";
LinkedList<Integer> out_list = new LinkedList<Integer>();
out_list.add(3);
out_list.add(5);
out_list.add(1);
serializeListToFile(out_list, file);
LinkedList<Integer> in_list = deserializeListFromFile(file);
while(!in_list.isEmpty()){
System.out.print(in_list.poll() + "-> ");
}
System.out.println("null");
}
}
/*
* Created on 10.01.2005@12:18:22
*
* TODO Explain me...
*/
package de.tutorials;
import java.beans.XMLDecoder;
import java.beans.XMLEncoder;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.LinkedList;
import java.util.List;
/**
* @author Darimont
*
* TODO Comment me
*/
public class XMLSerializerTest {
public static void main(String[] args) {
new XMLSerializerTest().doIt();
}
/**
*
*/
private void doIt() {
List list = new LinkedList();
list.add("AAA");
list.add("BBB");
list.add(new Foo());
try {
File file = new File("c:/myLinkedList.xml");
XMLEncoder encoder = new XMLEncoder(new FileOutputStream(file));
encoder.writeObject(list);
encoder.flush();
encoder.close();
XMLDecoder decoder = new XMLDecoder(new FileInputStream(file));
List lst = (List) decoder.readObject();
System.out.println(lst);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
/*
* Created on 10.01.2005@12:24:28
*
* TODO Explain me...
*/
package de.tutorials;
public class Foo {
int a = 10;
int b = 5;
public Foo() {
}
public String toString() {
// TODO Auto-generated method stub
return a + ":" + 5;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<java version="1.5.0" class="java.beans.XMLDecoder">
<object class="java.util.LinkedList">
<void method="add">
<string>AAA</string>
</void>
<void method="add">
<string>BBB</string>
</void>
<void method="add">
<object class="de.tutorials.Foo"/>
</void>
</object>
</java>
ZAntjeZ hat gesagt.:Ist vielleicht ne bloede Frage: aber was haben die eckigen Klammern LinkedList< Integer > zu sagen?