Hi forum,
I've got a question for the pros. I am making a program that has map<String, String> map = new TreeMap<String, String>();
and a Scanner to read a file contains some data which is assigned to map.put(); method. The data is something like this:
UK USA Canada Australia etc. The country names are separated with a "tab". All the data is on one line of a text file. I just want that when I print the country names and when system prints the data up to 5 tabs it will start a new line and then print the other 5 tabs and then again a new line and so on. I hope that someone will help me out.
import java.io.*;
import java.util.*;
public class Countries {
public static void main (String [] args) {
File file = new File("C:/Countries.txt");
Scanner reader = new Scanner(file);
Map<String, String> map = new TreeMap<String, String>();
String data[];
while(reader.hasNext()) {
data = reader.nextLine();
map.put(data[0], data[1]);
System.out.println(data);// printing data up to 4/5 tabs then break the line
System.out.println(data);// printing next 5 tabs and break the line and so on.
}
}
}