How do I name a file using Scanner? For some reason, Java's FileWriter won't accept a pre-defined String as an input. The code below is simplified to what I mean : `
import java.io.*;
public class Example{
public static void main(String[] arg) {
String title;
Scanner input = new Scanner(System.in);
title = input.next();
try {
FileWriter fw = new Filewriter(title);
} catch (IOException ex) {}
input.close()
}
}
I don't know why it doesn't work. I've checked other questions online and none of them seem to help.
EDIT: Okay, I edited the IOException and here's what I got from the stack trace;
java.io.FileNotFoundException: entries\awdwad
.txt (The filename, directory name, or volume label syntax is incorrect)
at java.base/java.io.FileOutputStream.open0(Native Method)
at java.base/java.io.FileOutputStream.open(FileOutputStream.java:292)
at java.base/java.io.FileOutputStream.<init>(FileOutputStream.java:235)
at java.base/java.io.FileOutputStream.<init>(FileOutputStream.java:156)
at java.base/java.io.FileWriter.<init>(FileWriter.java:82)
at main.JournalInput.main(JournalInput.java:26)
I'm sorry, I'm still confused about this.
EDIT EDIT: I found out the problem. There was a Delimiter I forgot and removing it apparently fixed it. I didn't put it in the code above either. Sorry for wasting everyone's time on this.