I'm working on an assignment that asks to request a file name, then take the file and output it to a .txt file with numbered line formatting like:
[001]
[002]
I have piece milled code together to get the program to work but I can't seem to get it to write in the requested format. Any help would be appreciated.
Here is my code so far.
try {
System.out.println("Enter your source code file name: ");
Scanner scanner = new Scanner(System.in);
String file = scanner.nextLine();
in = new FileInputStream(file);
out = new FileOutputStream(file + ".txt");
int c;
while ((c = in.read()) != -1) {
out.write(c);
}
} catch (IOException e) {
System.out.println("Error!");
}