私はxmlファイルを作成しており、デバイスコードに保存しています
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://xx:xx:xx:xx:yy/LoginAndroid.asmx/login");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
String responseBody = EntityUtils.toString(response.getEntity());
//Toast.makeText( getApplicationContext(),"responseBody: "+responseBody,Toast.LENGTH_SHORT).show();
//saving the file as a xml
FileOutputStream fOut = openFileOutput("loginData.xml",MODE_WORLD_READABLE);
OutputStreamWriter osw = new OutputStreamWriter(fOut);
osw.write(responseBody);
osw.flush();
osw.close();
//reading the file as xml
FileInputStream fIn = openFileInput("loginData.xml");
InputStreamReader isr = new InputStreamReader(fIn);
char[] inputBuffer = new char[responseBody.length()];
isr.read(inputBuffer);
String readString = new String(inputBuffer);
ファイルは保存されています。ファイルを読み取ることもできますが、すべて問題ありませんが、この行を見てください
char[] inputBuffer = new char[responseBody.length()];
ファイルの保存時に保存される文字列の長さを計算しています。あるアクティビティでファイルを保存し、別のアクティビティから読み取っています。アプリケーションはファイルをローカルに一度保存するため、長さを取得できませんでした毎回文字列を返すので、動的にサイズを割り当てる方法はありますか?char[] inputBuffer