如何将我的阅读器文件合并到我的程序中 [英] how can i incorporate my reader file to my program

查看:51
本文介绍了如何将我的阅读器文件合并到我的程序中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序可以读取我存储在数组中的有效帐号的值。我还有一个文件,从文本文件中读取有效的帐号。我需要从文本文件而不是数组中读取。


从数组中读取

展开 | 选择 | 换行 | 行号

解决方案

尝试构建一个类似于ReadMyFile()的方法,该方法返回一组有效帐户。当然,收集类型取决于您计划如何使用帐号。

展开 | 选择 | 换行 | 行号


< blockquote>我只是希望它基本上从validAccounts.txt文件检查以查看用户输入是否是有效帐户。


是否要每次重新加载文件进行检查,或者只读一次这个东西?


现在你所拥有的只是各种代码,可以解决你的问题。


我拿它你的任务是写一次性测试以查看帐号是否有效?


如果你不喜欢返回收藏品的方法,那就从程序上思考。


您可以使用当前文件读取例程在读取时进行测试 - 如果文件末尾没有找到匹配项,那么就没有匹配项。 (顺便说一句,我注意到你正在读取行,而不是整数值。你是否计划对字符串或整数进行比较?)


您可以将文件读取代码提升到您的isValid()方法。甚至进入主程序。


如果您需要帮助将文本字符串转换为整数,请查看Integer.decode(String)上的文档。


运气!


My program works reading from values that I have stored in an array for valid account numbers. I also have a file that reads the valid account numbers from a text file. I need to read from the text file and not the array.

reads from array

Expand|Select|Wrap|Line Numbers

解决方案

Try building a method similar to ReadMyFile(), which returns a collection of valid accounts. The type of collection would, of course, depend on how you are planning to use the account numbers.

Expand|Select|Wrap|Line Numbers


I just want it to basically check from the validAccounts.txt file to see if the users input is a valid account.


Do you want to reload the file every time for the check, or just read the thing once?

Right now all you have are miscellaneous code bits that sort of solve your problem.

I take it that your assignment is to write a one-shot test to see if the account number is valid?

If you don''t like the approach of returning a collection, then think procedurally.

You might use your current file read routine to test while reading - if no match is found by end-of file, then there is no match. (BTW, I notice that you are reading lines, not integer values. Were you planning on doing a comparison of strings or integers?)

You might hoist the file-read code to your isValid() method. Or even into the main routine.

If you need help converting text strings into integers, look up the documentation on Integer.decode(String).

Luck!


这篇关于如何将我的阅读器文件合并到我的程序中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆