I'm trying to write this program that'll generate 10 random values in a given range, store these numbers in a .txt file, and then read these numbers from the same file and display them on the screen with equivalent words.

I've got to the part where im trying to read the .txt file,
but JCreator kept spelling out ERROR:CANNOT FIND SYMBOL to the red line i highlighted below...
this is frustrating...I just couldn't see where i went wrong.


Thanks

///////////////////////////////////////////////////////////
import java.io.PrintWriter;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.Random;

public class Main {

public static void main(String arg[]){

int n[] = new int [10];
String fileName = "RandomNumbers.txt";
PrintWriter outputStream = null;
Scanner inputStream = null;

try
{
outputStream = new PrintWriter(fileName);
}
catch(FileNotFoundException e)
{
System.out.println("Error opening the file" + fileName);
System.exit(0);
}

for(int x=0; x<10; x++){
Random random = new Random();
int temp = random.nextInt(1000000);
n[x] = temp;
System.out.println(n[x]);
outputStream.println(n[x]);
}
outputStream.close();


try
{
inputStream = new Scanner(new file(fileName));
}
catch(FileNotFoundException e)
{
System.out.println("Error opening the file" + fileName);
System.exit(0);
}
inputStream.close();


}

}

///////////////////////////////////////////////////////////

Without "fixing" any of the code, I modified it enough to compile.

///////////////////////////////////////////////////////////
import java.io.*;
import java.util.*;
public class Main
{
   public static void main(String arg[])
   {
      int n[] = new int [10];
      String fileName = "RandomNumbers.txt";
      PrintWriter outputStream = null;
      Scanner inputStream = null;

      try
      {
         outputStream = new PrintWriter(fileName);

         int temp = 0;

         for(int x=0; x<10; x++)
         {
            Random random = new Random();
            temp = random.nextInt(1000000);
            n[x] = temp;
            System.out.println(n[x]);
            outputStream.println(n[x]);
         }

         outputStream.close();


         inputStream = new Scanner(new File(fileName));
         inputStream.close();
      }
      catch(FileNotFoundException e)
      {
         System.out.println("Error opening the file" + fileName);
         System.exit(0);
      }
   }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.