I was given a programming exercise which calls to: "Write a program to create a file named Exercise09_19.txt if it does not exist. Write 100 integers created randomly into the file using text I/O. Integers are separated by spaces in the file. Read the date back from the file and display the sorted data.
Look, I am not asking someone to do the assignment form me, but I can't, for the life of me, figure out how to store the random integers in the file and then read them back. I can create 100 random integers easily, and sorting them should be no problem but my book has too little information on the topic of reading and writing through text I/O!
PLEASE HELP ME WITH THE PROPER WAY TO STORE THE INTEGERS AND THEN READ THEM OUT OF A FILE, THROUGH THE USE OF TEXT I/O!
I realize no body want to write some one else's code but I'm in dire straights here. I need an example, or something, of how information is put into an IO file and then read out. I'm not asking for my program to be completed for me.
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
public class Exercise09_19 {
public static void main(String[] args) throws IOException {
java.io.File file1 = new java.io.File("Exercise09_19.txt");
if (file1.exists()) {
System.out.println("File Already exists.");
System.exit(0);
}
for (int i = 0; i < 100; i++) {
int x = (int) (Math.random() * 100);
//what do I do with this to get it into an IO file
}
}
}