help for writing to files in java -


hi have created class named 'human' each object of class has name , type can student or instructor. have created class main creates object of human , assign type , name objects , add objects linkedlist. want write linkedlist file,but dont know how. must write both objects , type linkedlist. have created following main class have problem in writing file parts. please guide me?

public class testing {      public static linkedlist<human> link =new linkedlist<human>();     static fileoutputstream fop;     public static void main(string args[])     {         file f=new file("textfile1.txt");         try {             fop=new fileoutputstream(f);         } catch (filenotfoundexception e) {             // todo auto-generated catch block             e.printstacktrace();         }           human hm = new human();         human hum = new human();         hm.setname("anna");         hm.settype("student");         hum.setname("elvis");         hum.settype("instructor");         link.add(hm);         link.add(hum);         (human h : link) {             fop.write(h.gettype());             fop.write(h);         }       } } 

look @ java.io.printstream

printstream p = new printstream(fop); (human h : link) {   p.println(h.gettype());   p.println(h); } p.close(); 

assuming have implemented tostring method human.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -