1
我有这个功能,当我调用它时,它不会返回任何东西。试图读取SD卡上的文件到变量
public String getfileFromSDCard(String filename){//get the file
String text;
text = "";
File root = new File(Environment.getExternalStorageDirectory(), "Notes");
if (!root.exists()) {
root.mkdirs();
}
File file = new File(root,"file.txt");
try {
BufferedReader br = new BufferedReader(new FileReader(file));
String str;
while ((str = br.readLine()) != null) {
text = text + str;
}
br.close();
}
catch (IOException e) {
e.printStackTrace();
}
Toast.makeText(this, text, Toast.LENGTH_SHORT).show();
return text;
}
我是否需要任何许可添加到我的Android manifiest以外
...使用许可权的android:NAME = “android.permission.WRITE_EXTERNAL_STORAGE” ......(我又写道这一行权在代码中)
我有这样一个已加入并运行,因为我可以很容易地编写一个文件,但我不能读它之后
这是我打电话是从的onCreate
功能TextView countDisplay = new TextView(this);
CreatefiletoSDCard("testnumberone.txt","22222fkdf sdjf hjsdf sdj fsdf ");
countDisplay.setText(getfileFromSDCard("testnumberone.txt"));
this.setContentView(countDisplay);
ps:CreatefiletoSDCard()的作品。
感谢,这是我的愚蠢的错误,我没看出来 – user1342645 2012-04-23 01:29:50