2011-04-14 4 views
0

그래서 난 그냥이 작업을 수행 할 수 있습니다 ++ C 알고 :텍스트 파일에서 형식 번호를 쉽게 얻을 수 있습니까?

ifstream file("data/maps/ssdebug1.cfg"); 
    string line; 
float startx = 0; 
    sscanf (line.c_str(), "start-x = %f;", &startx); 

그러나 자바에서이 작업을 수행 할 수있는 똑같이 쉬운 방법은 무엇입니까? 당신은 java.util.Scanner를 사용할 수 있습니다

자바에서
+0

의 NumberFormat 패키지에 http : //download.oracle.com/javase/1.4.2/docs/api/java/text/NumberFormat.html –

+0

또는 Scanner 클래스 ... – karakuricoder

답변

2

당신은 자바 버전 1.5에서

FileInputStream fis = new FileInputStream("data/maps/ssdebug1.cfg"); 
Properties prop = new Properties(); 
prop.load(fis); 
fis.close(); 

// you can have any number of properties with comments. 
// However, it is not assumed aline ends with a ';' 
String start_x = prop.getProperty("start-x"); 
double startx = Double.parseDouble(start_x); 
관련 문제