我已經讀取文件函數,它將讀取一個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個conections
0; 1; 500; //節點0與500 kbps的
1連接到節點1; 2; 500 //節點1連接到節點2 500 kbps的
當節點1被連接到節點2,它實際上還連接到節點0也是如此。這是否能夠把它放在一個hashmap?
我對此有點困惑。在此先感謝您的幫助。
你能舉一個例子說明文件的外觀如何,數據代表什麼以及如何讓它在一個有向圖中結束?我們並不知道你想要做什麼。 – jbx
嗨,我很抱歉,我已經遺漏了我的數據txt文件。我已經把我將在上面閱讀的示例txt文件。謝謝 – Eric