The Artima Developer Community
Sponsored Link

Java Answers Forum
how can i save the treeset on File

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Lena Kokoromiti

Posts: 4
Nickname: mike0303
Registered: Dec, 2002

how can i save the treeset on File Posted: Dec 18, 2002 12:49 PM
Reply to this message Reply
Advertisement
please help at new at java. i need to save the Set that i just cteated to disk and the load that set from disk?
What i am using in my codes doesnt work
thanks for u r time
public class TestSaveNumbers implements Serializable{


public static void main(String args[]) {

Numbers nu = new Numbers();
Numbers nu1 = new Numbers();
TreeSet a=new TreeSet(new Comp());


TreeSet b=new TreeSet(new Comp());

TreeSet c=new TreeSet(new Comp());

int max_range=30;
int total=4;
Integer number1;
Integer number2;
Integer ia;
int sequence=1;
int quantity;
int sequence1;
// for (int i=0;i<sequence;i++){
quantity=0;
sequence1 = ((int)(max_range*Math.random()+1));
nu.addNumbers(sequence1);
System.out.printl n(sequence1);
System.out.println("nu"+nu);
do{
number1 = new Integer((int)(max_range*Math.random()+1));
number2 = new Integer((int)(max_range*Math.random()+1));


//ia = Integer.valueOf(number1);
//ia = Integer.parseInt(number1);

//if (!a.contains(number1)){
a.add(number1);
//System.out.println("The Elements of First set:"+a);
String astring= String.valueOf(number1);
int ve = Integer.parseInt(astring);
//String.valueOf(astring);
//st.addState(astring);
b .add(number2);
//set.add(number1);

quantity++;
//}

}while(!(quantity==total));
Iterator i=a.iterator();
while(i.hasNext())
{
Object o=i.next();
//System.out.print(o+" ");
}

//nu.toString();
//System.out.println(nu);
String astring= String.valueOf(a);
//int ve = Integer.parseInt(astring);
//int mi= Integer.valueOf(ve);

String bstring= String.valueOf(b);
//System.out.println("The Elements Sorted"+set);
System.out.println("The Elements of First set:"+a);
System.out.println("The Elements of Second set:"+b);
//nu.addNumbers();
c.addAll(b);
c.addAll(a);
System.out.println("The Union of the two sets:"+c);
b.retainAll(a);
System.out.println ("The Intersection:"+b);



try {
// FileDialog dialog = new FileDialog(f, "select file");

String sourceFile="a:\\Numbers.txt";
FileOutputStream foStream = new FileOutputStream(sourceFile);
// ObjectOutputStream ooStream = new ObjectOutputStream(foStream);
foStream.write();

// ooStream.writeObject(a);
// ooStream.writeObject(a);

foStream.flush();
foStream.close();
} catch (Exception e) {
System.out.println("Error during output: "+e.toString());

}




try {

FileInputStream fiStream = new FileInputStream("a:\\Numbers.txt");
// ObjectInputStream oiStream = new ObjectInputStream(fiStream);
total=fiStream.read();
// a = oiStream.readObject();
// b= (Numbers) oiStream.readObject();





fiStream.close();
} catch (Exception e) {
System.out.println("Error during input: "+e.toString());
}


System.out.println(nu);
//System.out.println(a);
//if (a==nu){
//System.out.println("They Are equal");}
// if( nu.toString()==astring){ ///Why i cant get the true value?
///As you can see i tried differend ways
//But still i dont understand why doesnt return
//true value?
//System.out.println("They Are equal");

}

Topic: help with debug Previous Topic   Next Topic Topic: Yearning to write applications using JMS

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use