2
我想提出一個XML文件,並保存在我的設備代碼如下文件保存在Android
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()];
它計算可被保存在保存的file.I現在的儲蓄在一個Acivity的文件,並從另一個活動閱讀它和我的應用程序將文件保存到本地,一旦時間字符串的長度,所以我可以不能夠以獲得該返回的長度每次有n個字符串那麼有什麼辦法動態地分配char[] inputBuffer
的大小?
我需要知道有多少字符不行然後 **它給我錯誤'方法hasNext()是未定義的類型BufferedReader' ** – Anirban
答案更新,請看看。希望這是你所問的。 –
againg錯誤''不能對類型上下文''的非靜態方法openFileInput(String)進行靜態引用''InputStream is = Context.openFileInput(「loginData.xml」);' – Anirban