package readfile0; /** * * @author ernie */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { // Ask user for name of input file Scanner console = new Scanner(System.in); System.out.println("Input file: "); String inputFileName = console.next(); // Ask user for name of output file System.out.println("Output file: "); String outputFileName = console.next(); try { // construct a FileReader object using the name of the input file FileReader reader = new FileReader(inputFileName); // construct a PrintWriter object named out using the name of the output file PrintWriter out = new PrintWriter(outputFileName); } catch (FileNotFoundException e) { //in case the files aren't found we stop the program System.out.println("File not found!"); // Stop program if no file found System.exit(0); } // construct a Scanner object named in using the object named reader Scanner in = new Scanner(reader); int lineNumber = 1; while (in.hasNextLine()) { String line = in.nextLine(); out.println("/* " + lineNumber + " */ " + line); lineNumber++; } out.close(); } }