公共無效AddLocationHandler()拋出IOException異常 {
String name = ((EditText) findViewById(R.id.nameText)).getText().toString();
String longi = ((EditText) findViewById(R.id.longText)).getText().toString();
String lati = ((EditText) findViewById(R.id.latText)).getText().toString();
String timezone = ((EditText) findViewById(R.id.timeText)).getText().toString();
Double locationLong;
Double loctaionLat;
TimeZone locationTimeZone;
try {
loctaionLat = parseDouble(lati);
}catch (NumberFormatException e)
{
Toast toast = Toast.makeText(getApplicationContext(), "not a valid latitude ", Toast.LENGTH_SHORT);
toast.show();
return;
}
try {
locationLong = parseDouble(longi);
}catch (NumberFormatException e)
{
Toast toast = Toast.makeText(getApplicationContext(), "not a valid longitude ", Toast.LENGTH_SHORT);
toast.show();
return;
}
if(timezone.matches("(\\+|\\-)[0-1][0-9]\\:[034][05]")){
locationTimeZone = TimeZone.getTimeZone("GMT" + timezone);
}
else
{
Toast toast = Toast.makeText(getApplicationContext(), "not a valid Time Zone ", Toast.LENGTH_SHORT);
toast.show();
return;
}
File file = new File("au_location.txt");
if(!file.exists()){
file = new File(getFilesDir(), "au_location.txt");
}
FileOutputStream fos = openFileOutput("au_locations.txt", Context.MODE_APPEND);
OutputStreamWriter f = new OutputStreamWriter(fos);
f.write(name + "," +loctaionLat + "," + locationLong + "," + "GMT" + timezone + "\n");
//fos.write(s.getBytes());
//fos.close();
Toast.makeText(getBaseContext(),"Data Saved", Toast.LENGTH_LONG).show();
f.flush();
f.close();
Toast.makeText(getBaseContext(),"New Location Added", Toast.LENGTH_LONG).show();
}
您是通過劈裂線 - ''。那麼你正在接受wordOnLine--你確定每條線都以昏迷結束嗎?另外檢查這一個:http://stackoverflow.com/questions/454908/split-java-string-by-new-line – X3Btel
謝謝,爲您的答覆。是的,每一行都需要有一個camma,因爲我必須從文件中讀取以下文本。格倫莫公園,-33.79068,150.6693,澳大利亞/悉尼 – nadia
@nadia我認爲你需要有2個循環,1.對於每行按\ n分割和循環直到用line.length來分割你的文本每行',' – Sodiq