【发布时间】:2014-09-08 08:37:41
【问题描述】:
我尝试在 return 语句之前放一个 toast,但 String 变量返回一个空字符串。
public String getXmlFile(String pathFile, Context context){
String xmlFileString = "";
AssetManager am = context.getAssets();
try {
InputStream str = am.open(pathFile);
int length = str.available();
byte[] data = new byte[length];
xmlFileString = new String(data);
} catch (IOException e1) {
e1.printStackTrace();
}
return xmlFileString;
}
【问题讨论】:
-
因为你从来没有从流中读取
-
你没有把
InputStream读成data -
我已经发布了答案,试试吧..