写入文件异常?
我让程序的用户在按下 GUI 中的按钮后在 JOptionPane
中输入信息。该信息被写入文本文件。我希望发生异常,如果他们输入的信息不是正确数量的令牌,则会出现一条消息。
我用字符串标记器分割了文件的每一行,每行有七个标记,其中分隔符是逗号。因此,如果用户只输入三个令牌,我希望显示一条错误消息。
遇到这个问题时,任何帮助都会很棒。谢谢。
I'm having the user of my program enter information in a JOptionPane
after pressing a button in a GUI. The information is written to a text file. I would like to have an exception happen and a message appear if the information they enter is not the right amount of tokens.
I've split up each line of the file with the string tokenizer, and each line has seven tokens, which the delimiter being a comma. So if the user lets say enters only three tokens, I would like an error message displayed.
Having trouble with this one, any help would be amazing. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想说例外是针对特殊情况的。这类似于错误检查 101。
只需检查用户是否拥有正确数量的代币并向他显示所需的错误。
不要让事情过于复杂化。
I would say exceptions are for EXCEPTIONAL situations. This seams like error checking 101.
Just check if the user has the correct amount of tokens and show him the desired error.
Don't over complicate things.