Content of a file:
Afganistan,5,1,648,16,10,2,0,3,5,1,1,0,1,1,1,0,green,0,0,0,0,1,0,0,1,0,0,black,green
Albania,3,1,29,3,6,6,0,0,3,1,0,0,1,0,1,0,red,0,0,0,0,1,0,0,0,1,0,red,red
Algeria,4,1,2388,20,8,2,2,0,3,1,1,0,0,1,0,0,green,0,0,0,0,1,1,0,0,0,0,green,white
American-Samoa,6,3,0,0,1,1,0,0,5,1,0,1,1,1,0,1,blue,0,0,0,0,0,0,1,1,1,0,blue,red
Andorra,3,1,0,0,6,0,3,0,3,1,0,1,1,0,0,0,gold,0,0,0,0,0,0,0,0,0,0,blue,red
Angola,4,2,1247,7,10,5,0,2,3,1,0,0,1,0,1,0,red,0,0,0,0,1,0,0,1,0,0,red,black
Anguilla,1,4,0,0,1,1,0,1,3,0,0,1,0,1,0,1,white,0,0,0,0,0,0,0,0,1,0,white,blue
I need to remove "," from the lines and put each line into an array separately.
The content of one line should be separate from other line using java
I used ArrayList
but array includes commas.
Please help me remove "," from each line.
This is the code I have used so far:
String filePath = "/home/pavan/Desktop/flag.data";
try
{
BufferedReader lineReader = new BufferedReader(new FileReader(filePath));
String lineText = null;
List<String> listLines = new ArrayList<String>();
while ((lineText = lineReader.readLine()) != null)
{
String a = lineText.replaceAll(",", "");
listLines.add(a);
}
lineReader.close();
for (String line : listLines)
{
System.out.println(line);
}
}catch(IOException ex){
System.err.println(ex);
}
String [] newArray = yourString.split(",");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.