java读取txt

来源:互联网 发布:京东秒杀软件手机版 编辑:程序博客网 时间:2024/04/29 19:40
public static void main(String[] args) {  try{   File file = new File("E:\\a.txt");//创建文件对象   BufferedReader br = new BufferedReader(new FileReader(file)); //创建读取流   //读取数据   String temp = br.readLine();   String line;   while((line = br.readLine()) != null){    temp += "," + line;   }   if(temp == null){    System.out.println();   }else{    //分割字符串    String []str =  temp.split(",");    //创建double数组并赋值    Double[] d = new Double[str.length];     for(int i = 0 ;i < str.length ;i++){     d[i] = Double.parseDouble(str[i]);    }    //打印double数组    for(int i = 0 ; i < d.length ; i++){     System.out.println(d[i]);    }   }  }catch(Exception e){     }

原创粉丝点击