Switch to full style
General Java code examples
Post a reply

Write Vector list to File

Thu Feb 07, 2013 8:00 pm

Write Vector list to File
java code
import java.io.*;
import java.util.Vector;

public class VectorToFile {
private Vector victor;
private static final int size = 10;

public VectorToFile () {
victor = new Vector(size);
for (int i = 0; i < size; i++)
victor.addElement(new Integer(i));
}
public void writeList() {
PrintStream out = null;

try {
System.out.println("Start writing to file.");
out = new PrintStream(new FileOutputStream("file.txt"));

for (int i = 0; i < size; i++)
out.println("Value at: " + i + " = " + victor.elementAt(i));
} catch (ArrayIndexOutOfBoundsException e) {
System.err.println("ArrayIndexOutOfBoundsException Error:" +
e.getMessage());
} catch (IOException e) {
System.err.println("IOException: " + e.getMessage());
} finally {
if (out != null) {
System.out.println("PrintStream");
out.close();
} else {
System.out.println("Couldn't open connection");
}
}
}
}




Post a reply
  Related Posts  to : Write Vector list to File
 How to write a PHP coding to list out all files and director     -  
 Write to file using php     -  
 File write read     -  
 Read and write CSV file     -  
 Read and Write to file using ASP     -  
 How to read and write to CSV file from python     -  
 Write and Read to File In Java Example     -  
 Iterator on Vector     -  
 vector front     -  
 Vector class     -  

Topic Tags

Java Files and I/O