i want to read some data from a text file.for example:
1 // total 1 client data
192.168.1.116;pc3;/home/pc3/Documents;C:/user/windows/Desktop; // details of client data.
and this is my code:
String strLine;
String [] values = new String[4];
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
{
for (int i = 0; i < tokens.length; i++)
{
values[i] = tokens[i];
}
dc = new DisplayClient(clientCounter,values[0],values[1]," ",values[2],values[3]);
clientList.add(dc);
but now the file that i need to read have few delimiters. For example:
0:1,0.5,2,0.7,3,0.2; // 7 items
1:0,0.5,7,1;//5 items
2:0,0.7;// 3 items
i am using this data to create a p2p simulation.
2:0,0.7;//means Node 2 is connected to Node 0 with bandwidth 700kbps
1:0,0.5,7,1;//means Node 1 is connected to Node 0 with 500kbps and Node 1 is also connected to Node 7 with 1000kbps(1mbps).
but now it have 3 delimiters and the item of node maybe be static. It might be 3 items or 5 items or 7 items or might be more. how can i read this and let differentiate each data with delimiter ??
Sorry for my ignorance and thanks in advance for help.
I would try this: