// Get the text file
File file = new File(Environment.getExternalStorageDirectory()
+ "/Config/GPSListenerminTime.cfg");
// Read text from file
StringBuilder GPSListenerminTime = new StringBuilder();
try {
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
while ((line = br.readLine()) != null) {
GPSListenerminTime.append(line);
GPSListenerminTime.append('\n');
}
} catch (IOException e) {
// TODO You'll need to add proper error handling here
}
我想使用此代码从文件中读取一个数字,它运行良好,但我如何在 requestLocationUpdates 中使用该数字作为长值?我试图以这种方式使用它,但它不起作用:
lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, Long.valueOf(String.valueOf(GPSListenerminTime)), 0, this);
我的文件只包含这个数字:10000 我在启动服务时收到这个错误:
08-07 15:32:45.599: E/AndroidRuntime(19878): java.lang.RuntimeException:
Unable to create service com.example.gpslog.DataLogService: java.lang.NumberFormatException: 10000