最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
java怎么读第二行?java如何跳过第一行从第二行开始读?
时间:2017-02-16 编辑:简简单单 来源:一聚教程网
代码如下 | 复制代码 |
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; } } |
相关文章
- SpringBoot测试配置属性与web启动环境解析 10-24
- vue中将el-switch值true、false改为number类型的1和0解析 10-24
- Vue中的路由配置项meta使用解读 10-24
- SpringBoot自定义bean绑定解析 10-24
- SpringBoot常用计量与bean属性校验和进制数据转换规则解析 10-24
- 工厂方法在Spring框架中的运用介绍 10-24