Please I am trying to get this code to output in .txt file: I need your help: import java.io.File; // Import the File class import java.io.FileNotFoundException; // Import this class to handle errors // Import the Scanner class to read text files import java.util.*; import java.io.*; public class KMeans { List<double []> clusterCentroids; Map<Integer,List<Double>> dataMatrix; List<double[]> data; Integer numClusters; public void writeFile(List<Double> value, File filename) { try { FileWriter myWriter = new FileWriter(filename); myWriter.write(value.toString()); myWriter.close(); System.out.println("Successfully wrote to the file."); } catch (IOException e) { System.out.println("An error occurred."); e.printStackTrace(); } } public KMeans() { data = new ArrayList<double []>(); dataMatrix = new LinkedHashMap<>(); } void readData(String filePath, int n, List<Double> c) { numClusters = n; try { BufferedReader br = new BufferedReader(new FileReader(new File(filePath))); String line; int i = 0; while((line = br.readLine()) != null) { String [] elem = line.split("\\s+"); int j = 0; for(String d : elem) { if(isCentroid(j, c)) { this.clusterCentroids.get(i)[j] = ((Double.valueOf(d))); } //data.get(i)[j] = ((Double.valueOf(d))); System.out.println(data.get(j)[i]); } System.out.println(); i++; } br.close(); } catch (IOException ex) { ex.printStackTrace(); } } private boolean isCentroid(int j, List<Double> c) { for(int i = 0; i < c.size(); i++) { if(j == c.get(i)) { return true; } } return false; } public static void main(String [] args) { Scanner sc = new Scanner(System.in); List<Double> centroids = new ArrayList<>(); String filePath = ("C:\\Users\\mamdo\\eclipse- workspace\\K_project\\src\\synthetic_control_data.txt"); int n = 6; for(int i=0;i<n;i++) { Random r = new Random(); centroids.add((double)r.nextInt(600)+1); } System.out.println("Initial Clusters Centroids : " + centroids); KMeans km = new KMeans(); //km.readData(filePath,n,centroids); //km.calc(); } } .