Although you are creating a File
object, you are not telling it to create it in the filesystem.
String className = this.getClass().getSimpleName();
String fileName = String.format("%s.txt", className);
try {
new File(fileName).createNewFile();
} catch (IOException e) {
throw new RuntimeException(String.format("Error creating new file '%s'", fileName), e);
}
I also think you might want to use getSimpleName
instead of getName
. getName
will get you the entire package and class name (com.package.ClassName
) whereas getSimpleName
will just get the class name (ClassName
)