我有读取文件功能,它将读取一个 txt 文件。读完后,我将值放入列表中。以下是样本数据:
public void readDisplayClient()
{
DisplayClient dc = null;
try
{
// Open the file that is the first
// command line parameter
FileInputStream fstream = new FileInputStream("ClientData.txt");
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
String [] values = new String[3];
int counter = 0;
int clientCounter = 0;
//Read File Line By Line
while ((strLine = br.readLine()) != null)
{
// Print the content on the console
String delims = ";";
String[] tokens = strLine.split(delims);
if(counter == 0)//Reading total clients
{
totalClient = Integer.parseInt(tokens[0]);
counter++;
}
else
{
//System.out.println("Test " + counter + " " + tokens.length);
for (int i = 0; i < tokens.length; i++)
{
values[i] = tokens[i];
//System.out.println(tokens[i]);
}
dc = new DisplayClient(clientCounter,values[0],values[1],values[2]);
//dc.printDetails(); // save the connected nodes details to logger txt file.
clientList.add(dc);
clientCounter++;
}
}
//Close the input stream
in.close();
ss.setTotalClient(totalClient);
ss.setClientList(clientList);
//ss.printClientList();
}
catch (Exception e)
{//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
我的 txt 数据文件将类似于:
2// 共 2 个连接
0;1;500; // 节点 0 以 500 kbps 连接到节点 1
1;2;500 // 节点 1 以 500 kbps 连接到节点 2
当节点 1 连接到节点 2 时,它实际上也连接到节点 0。这能把它放在哈希图上吗?
我对此有点困惑。提前感谢您的帮助。