我指定了这些文件地址data/data/org.com.Cache/files/cacheImplementationOutput
,但我收到以下错误消息.....
java.io.IOException: Couldn't open /data/data/org.com.Cache/files/cacheImplementationOutput
答案 0 :(得分:1)
将方法名称称为fetch(url,outputXml);
并将xml内容读作.... FileInputStream fis = openFileInput(outputXml);
public byte [] readBytes(InputStream inputStream,String outputXml){ 尝试{ ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream(); int bufferSize = 1024; byte [] buffer = new byte [bufferSize]; OutputStreamWriter fout = new OutputStreamWriter(openFileOutput( outputXml,0)); int len = 0; while((len = inputStream.read(buffer))!= -1){ byteBuffer.write(buffer,0,len); } fout.write(new String(byteBuffer.toByteArray())); fout.close(); return byteBuffer.toByteArray(); } catch(NullPointerException e){ e.printStackTrace(); } catch(例外e){ } return null;
}
public void fetch(URL url, String outputXml) {
try {
InputStream myInputStream = null;
StringBuilder sb = new StringBuilder();
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/xml");
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(sb.toString());
wr.flush();
wr.close();
myInputStream = conn.getInputStream();
readBytes(myInputStream, outputXml);
System.out.println("writing is done");
}catch (NullPointerException e) {
e.printStackTrace();
}
catch (Exception e) {
}
}
答案 1 :(得分:0)
您忘记了商店地址开头的/
...
所以data/data/org.com.Cache/files/cacheImplementationOutput
就像data/data/org.com.Cache/data/data/org.com.Cache/files/cacheImplementationOutput