I need to rename the file temp.txt
later on in my code. I tried doing this with the newFile = new File(name);
line, but this just created a new file entirely. Could you point me in the right direction here?
public static File InputOutput (Scanner console, int in_Out) throws
FileNotFoundException {
//<editor-fold>
String name = "newName";
String line = "";
String in_OutText = "";
File newFile = new File("temp.txt");
for (int i = 0; i <= in_Out; i++) {
if (i == 0) {
in_OutText = "Input";
} else {
in_OutText = "Output";
}
System.out.print(in_OutText + " file name: ");
name = console.next();
if (i == 1) {
newFile = new File(name);
}
}
PrintStream inputCopy = new PrintStream(newFile)
Scanner input = new Scanner(name);
while (input.hasNextLine()) {
line = input.nextLine();
inputCopy.println(line);
inputCopy.println("WORKED");
}
return newFile;
}
Thanks!