将文本文件中转储的文本转换为 Csv 和数组
我一直在使用 actionListener
将文本从多个 TextFields
传递到名为 writetouser.txt
的文本文件中,尽管我注意到这个,但效果很好文本只是转储并且不是数组的格式。出于此应用程序的目的,我有必要能够搜索此文本文件并根据输入的搜索显示值。我有一个文件,它从文本文件中读取数据,并尝试将数据转换为 CSV,以便它可以作为数组读取。我想知道必须输入什么而不是 user, pass 才能从文件 writetouser.txt
中获取文本。
附录:
public void ReadUser()
{
try{
// Open the file
FileInputStream fstream = new FileInputStream("writetouser.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
String strLine;
//Read File Line By Line
while ((strLine = br.readLine()) != null) {
// Print the content on the console
//System.out.println (strLine);
String[] items = strLine.split(",");
String[][] usersArray = new String [10][2];
for (String item : items) {
System.out.println(item);
}
}
//Close the input stream
in.close();
}catch (Exception e){
//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
} 这
是我试图分离的数据的示例。 输入到文本文件中
inputUser = user + ", " + pass;
writetouser.WriteToUser(inputUser);
它作为dburgess, 2345
i have been using an actionListener
to pass text from numerous TextFields
into a text file named writetouser.txt
this works fine though i have noticed that this text is just dumped and is not in the format of an array. For the purposes of this application it is necessary that i am able to search this text file and show values based on searches entered. I have a file which reads the data from the text file and have attempted to convert the data to CSV
's so it is is readable as an array. i am wondering what must be entered instead of user, pass in order to take the text from inside the filewritetouser.txt
.
Addendum:
public void ReadUser()
{
try{
// Open the file
FileInputStream fstream = new FileInputStream("writetouser.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
String strLine;
//Read File Line By Line
while ((strLine = br.readLine()) != null) {
// Print the content on the console
//System.out.println (strLine);
String[] items = strLine.split(",");
String[][] usersArray = new String [10][2];
for (String item : items) {
System.out.println(item);
}
}
//Close the input stream
in.close();
}catch (Exception e){
//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
}
here is an example of the data which i am trying to separate. it is entered into textfile as
inputUser = user + ", " + pass;
writetouser.WriteToUser(inputUser);
dburgess, 2345
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我想你想要的是:
I think what you want is:
我注意到这一行被注释掉了:
这对我来说表明您可能试图确保从文件中获得您期望的行。如果您得到您所期望的结果,我们就可以继续前进。如果不是,则说明文件的读取方式存在问题,或者数据的格式不符合您的预期。
如果到目前为止一切顺利,我们就已经解决了解析和显示文件内容的问题。我假设您正在尝试将文件的内容写入终端并期望一种格式,但得到另一种格式。
我想您现在会看到类似这样的内容:
(打印的用户名/密码对不超过 1 个)。
我猜你想要这样的东西:
那里有很多假设(我仍然不完全确定你想要做什么)——如果这些假设是正确的,让我知道;我将发布一些格式化提示。
I notice that this line is commented out:
Which suggests to me that you were probably trying to ensure that you're getting the line you expect from your file. If you are getting what you expect, we're clear to move on. If not, there's a problem in how the file is being read, or the data isn't formatted how you expect.
If we're good so far, we've arrived at the problem of parsing and displaying the content of the file. I'm assuming that you're trying to write the contents of the file to your terminal and expecting one format, but getting another.
I think what you'll see right now is something like this:
(with no more than 1 username/password pair printed).
And I'm guessing you want something like this:
There are a lot of assumptions there (I'm still not entirely sure what you're trying to do) -- if those assumptions are correct, let me know; I'll post some formatting tips.
在检查我的代码后,我注意到下面的两段代码正在做完全相同的事情,这就是为什么我每条信息都会出现两次。
甲乙
Upon reviewing my code i noticed that the two pieces of code below were doing the exact same thing which is why i was being presented with each piece of info twice.
A
B