public class BufferedReaderTest
{
public static void main(String[] args)
{
/**
* 3.txt
* 3
* Rajgarh, Rajasthan
* 75.38
* 28.63
* Mbini, Equatorial Guinea
* 9.62
* 1.58
* Divo, Ivory Coast
* -5.37
* 5.85
*/
try
{
BufferedReader reader = new BufferedReader(new FileReader("C:\\3.txt"));
String readline = reader.readLine();
int length = Integer.parseInt(readline);
City[] citys = new City[length];
while(length > 0)
{
String name = reader.readLine();
double latCord = Double.parseDouble(reader.readLine());
double longCord = Double.parseDouble(reader.readLine());
citys[citys.length - length] = new City(name, latCord, longCord);
length--;
}
reader.close();
for(City c : citys)
{
System.out.println(c);
}
}
catch (FileNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
System.err.println("文件内容缺失!!!");
}
}
}
class City {
String name;
double latCord;
double longCord;
public City(String name, double latCord, double longCord)
{
this.name = name;
this.latCord = latCord;
this.longCord = longCord;
}
public String toString()
{
return "name=" + name
+ ",latCord=" + latCord
+ ",longCord=" + longCord;
}
}