Writing an interger array to file

92 Views Asked by At

I have created a small file to generate an a random interger array of specified length. My problem is that I am having difficulty in writing the file to a txt file which will then be used as an argument in a sorting algorithm.The errors occurs in the bufferedWriter.

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.util.Arrays;
import java.util.Random;

    public static void main(String[] args) {
        GenerateRandomArray randomizer = new GenerateRandomArray();
// Generate an array of size 10 from -31 to 0.
        int[] x= randomizer.generator(10,-31,0);

        BufferedWriter outputWriter = null;
        outputWriter = new BufferedWriter(new FileWriter(10.txt));
        for (int i = 0; i < x.length; i++) {
        outputWriter.write(Integer.toString(x[i]));
        outputWriter.newLine();
      }
        outputWriter.flush();  
        outputWriter.close();

        System.out.print(Arrays.toString(x));        

    }
    }
1

There are 1 best solutions below

0
On BEST ANSWER

You need to pass File object or String with file name in coonstructor

outputWriter = new BufferedWriter(new FileWriter("10.txt"));