极其简单的 Java IO 和枚举问题
我知道我缺少一些非常简单的东西,但以下代码不会使用 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 ConfigureSettings();
}
}
我的枚举问题是我可以创建枚举的枚举吗?我的意思是我可以将我拥有的三个当前枚举变量(Dodge Damage 和 DPS)包装在超级枚举类中吗?
PS我知道我的代码显示不正确,对未来的帖子/编辑有什么提示吗?
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 ConfigureSettings();
}
}
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
关于缺少
println
输出:您是否在println
之后尝试过flush
PrintWriter
,并在不再需要时显式关闭
它?至于你的枚举的枚举问题 - 枚举的枚举有什么用处?你的意思是这样的吗(我刚刚编造的——我很确定它不会编译):
你会用这样一个复杂的枚举做什么?为什么不简单地:
然后使用这个枚举而不是其他三个,因为它们都包含相同的枚举值?
(更新:但是请注意,使用相同的枚举而不是三个单独的枚举很可能会降低代码的类型安全性,因此上述建议可能不一定是一件好事。)
Concerning the missing
println
output: Have you triedflush
ing thePrintWriter
afterprintln
, and explicitlyclose
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):
What would you do with such a complicated enum? Why not simply:
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.)