나는 두 배의 목록이있는 텍스트 파일을 가지고 있습니다. 선의 첫 번째 값은 x 값이고 두 번째 값은 y 값입니다.arrayList에로드가 두 배로 늘어납니다.
103.0 274.0
133.0 383.0
342.0 250.0
204.0 126.0
177.0 357.0
...
어떻게이 값을 읽고 배열 목록에로드 할 수 있습니까?
ArrayList<Point> store = new ArrayList<Point>();
File file = fc.getSelectedFile();
StringBuilder all = new StringBuilder();
BufferedReader reader = new BufferedReader(new FileReader(file));
String input = null;
while ((input = reader.readLine()) != null)
{
String a = all.append(input+"\n").toString();
String[] hold = a.split(" ");
double x = Double.parseDouble(hold[0]);
int aa = (int)(x);
double y = Double.parseDouble(hold[1]);
int bb = (int)(y);
store.add(new Point(aa, bb));
}
이다 http://stackoverflow.com/questions/1855753/reading- double-values-from-file –
코드를 포맷 할 때 좀 더주의를 기울여주십시오. (이 포럼은 탭을 부드럽게 처리 할 수 없습니다. 특히 공백으로 섞을 때 ---) 볼 수 있듯이 – kleopatra