How can I get what i'm reading in from a file to an output file : I'm able to pull out the 20 names randomly but how do I store them in a output file rather then displaying them to the screen? I tried filewriter but couldn't get it to work.

    public class Assignment2 {
    
        public static void main(String[] args) throws IOException 
    {
    // Read in the file into a list of strings
    BufferedReader reader = new BufferedReader(new FileReader("textfile.txt"));
    //BufferedWriter bw = new BufferedWriter(new FileWriter("out.txt"));
    List<String> lines = new ArrayList<String>();
    
    String line = reader.readLine();
    
    while( line != null ) {
        lines.add(line);
        line = reader.readLine();
    }
    
    // Choose a random one from the list
    Random r = new Random();
    FileWriter letters = new FileWriter("out.txt");
    for (int i = 0; i < 20; i++) 
    {
        
       int rowNum = r.nextInt(lines.size ());
       System.out.println(lines.get(rowNum));
    }
    
    }
    }