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は500kbpsでノード1に接続します
1; 2;500//ノード1は500kbpsでノード2に接続します
ノード1がノード2に接続されている場合、実際にはノード0にも接続されています。これはそれをハッシュマップに載せることができますか?
少し混乱しています。助けてくれてありがとう。