Read and Write with java from one file to another
<p>How do I read the following information from a txt file and write just the numbers to another text file using Java? I have it displaying to the console but it will not write to the file also.</p>

<blockquote>
  <p>Jones 369218658389641<br>
  Smith 6011781008881301<br>
  Wayne 5551066751345482<br>
  Wines 4809134775860430<br>
  Biggie    9925689541232325<br>
  Luke  7586425896325410<br>
  Brandy    4388576018410707<br>
  Ryan  2458912425860439</p>
</blockquote>

<pre><code>import java.util.Scanner;
import java.io.File;

public class test {
public static void main(String[] args) throws Exception {
    // Create a File instance
    java.io.File file = new java.io.File("accounts.txt");
    // Create a Scanner for the file
    Scanner input = new Scanner(file);
    // Read data from a file
    while (input.hasNext()) {
        String accountName = input.next();
        Long cardNumber = input.nextLong();
//this is where I want to write just the numbers to a file called cardnums.txt          
        file = new java.io.File("cardnums.txt"); 
        java.io.PrintWriter output = new java.io.PrintWriter(file); 
        output.println(cardNumber);
        System.out.println(cardNumber);
    }
    // Close the file
    input.close();

}
}
</code></pre>

<p>I got it now.</p>

<pre><code>import java.util.Scanner;
import java.io.File;

public class test {
public static void main(String[] args) throws Exception {
    // Create a File instance
    java.io.File file = new java.io.File("accounts.txt");
    // Create a Scanner for the file
    Scanner input = new Scanner(file);
    // Read data from a file
    file = new java.io.File("cardnums.txt"); 
    java.io.PrintWriter output = new java.io.PrintWriter(file); 
    while (input.hasNext()) {
        String accountName = input.next();
        Long cardNumber = input.nextLong();
//this is where I want to write just the numbers to a file called credit.txt            
        output.println(cardNumber);
        System.out.println(cardNumber);
    }
    // Close the file
    input.close();
    output.flush();
    output.close();
}
}
</code></pre>