[英]Java Program to read text file
I have a text file like 我有一个像文本文件
vinoth 5001 chennai programmer
ramesh 7755 madurai tester
suresh 7452 namakal designer
salim 4652 salem programmer
I want to find with their designation but want to save their other details in an array. 我想找到他们的名称但想要将他们的其他细节保存在一个数组中。 how can i do that? 我怎样才能做到这一点? any suggestions 有什么建议么
String.substring(start, end)
to get the relevant part of the line. 使用String.substring(start, end)
来获取该行的相关部分。 trim()
on it. 调用trim()
就可以了。 String.split
to split the different informations into an array 调用String.split
将不同的信息拆分成一个数组 Map
whose key would be the username vinoth
and values would be the array you just received from String.split
您可以将这些信息存储在一个Map
该键的关键字是用户名vinoth
,值将是您刚从String.split
收到的数组。 Read each line using buffered reader and then do that: 使用缓冲读取器读取每一行,然后执行以下操作:
HashMap<String, String> values = new HashMap<String, String>;
// read the line here
String line = ...;
String strings[] = line.split(" ");
String designation = strings[3];
values.put(strings[0], strings[1], strings[2]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.