I just started learning how to write into file and read from a file on java oi. Now I can write simple text into a file and also can read it using system.out.print. The problem now is, I tried to create an array and store it in a file using the same way I learnt, but when I run the program the file is created but there was nothing to display. Please is there any thing I can do otherwise, below is the sample of my codes:
public static void main(String[] args) throws FileNotFoundException {
// TODO Auto-generated method stub
File Veggies= new File ("C:\\Users\\user\\Desktop\\My Java Files\\Product.txt");
if(Veggies.exists())
System.exit(0);
PrintWriter output= new PrintWriter(Veggies);
output.println("These are the list of our products.");
String[] VeggiesArray={"Apples","Bananas","Oranges","Avocados","Strawberries"};
for(int i=0;i<=VeggiesArray.length;i++){
output.println("(" + i + ")" +" "+ VeggiesArray[i]);
}
output.close();
}