How can I read comma separated values from a text file in Java?

后端 未结 6 794
轮回少年
轮回少年 2020-12-01 13:45

I have got this text file with latitude and longitude values of different points on a map.

How can I split my string into latitudes and longitudes? What is the gener

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-01 14:09

    //lat=3434&lon=yy38&rd=1.0&| in that format o/p is displaying

    public class ReadText {
        public static void main(String[] args) throws Exception {
            FileInputStream f= new FileInputStream("D:/workplace/sample/bookstore.txt");
            BufferedReader br = new BufferedReader(new InputStreamReader(f));
            String strline;
            StringBuffer sb = new StringBuffer();
            while ((strline = br.readLine()) != null)
            {
                String[] arraylist=StringUtils.split(strline, ",");
                if(arraylist.length == 2){
                    sb.append("lat=").append(StringUtils.trim(arraylist[0])).append("&lon=").append(StringUtils.trim(arraylist[1])).append("&rt=1.0&|");
    
                } else {
                    System.out.println("Error: "+strline);
                }
            }
            System.out.println("Data: "+sb.toString());
        }
    }
    

提交回复
热议问题