Dead Simple Java IO & Enum Question
I know there is something dead simple I'm missing, but the following code won't write the text using println
:
import java.io.*;
import javax.swing.JOptionPane;
public class ConfigureSettings{
private PrintWriter SettingsFile;
private enum Dodge{
Ascending, Descending, Off
};
private enum Damage{
Ascending, Descending, Off
};
private enum DPS{
Ascending, Descending, Off
};
ConfigureSettings(){
try{
SettingsFile = new PrintWriter(new File("UserSettings"));
}
catch(IOException e){
JOptionPane.showMessageDialog(null, "Sorry cannot open UserSettings File");
}
SettingsFile.println("k");
JOptionPane.showMessageDialog(null, "Done");
}
public static void main(String args[]){
new Con开发者_如何学编程figureSettings();
}
}
My Enumeration question is can I create an Enumeration of Enumeration's? I mean can I wrap the three current enum variables I have, Dodge Damage and DPS, in Super enum class?
P.S. I know my code isn't displaying correctly, any hints for future posts/edits?
Concerning the missing println
output: Have you tried flush
ing the PrintWriter
after println
, and explicitly close
ing it when you no longer need it?
As to your enum of enums question — what would an enum of enums be good for? Do you mean something like this (which I just made up — I'm quite sure it won't compile):
private enum Enumenum {
enum Dodge {
Ascending, Descending, Off
},
enum Damage {
Ascending, Descending, Off
},
enum DPS {
Ascending, Descending, Off
}
}
What would you do with such a complicated enum? Why not simply:
enum OneForAll {
Ascending, Descending, Off
}
And then use this enum instead of the other three, since they all contain the same enumeration values anyway?
(Update: Note however that using the same enum instead of three separate enums might very well reduce the type safety of your code, so the above suggestion might not necessarily be a good thing.)
精彩评论