我有这个代码:
try {
URL url = new URL (strURL);
input = url.openStream();
byte[] buffer = new byte[1500];
OutputStream output = new FileOutputStream ("/sdcard/"+pos+".png");
Run Code Online (Sandbox Code Playgroud)
我得到这个错误:不要硬编码/ SD卡/使用environment.getexternalstoragedirectory().getpath()而不是
OutputStream output = new FileOutputStream ("/sdcard/"+pos+".png");
Run Code Online (Sandbox Code Playgroud)
我已经读过:Android 4.2 - Environment.getExternalStorageDirectory().getPath()行为
所以问题是当我更换它时最终代码是什么?
sd文件夹名称在某些手机中有所不同
在三星手机中,它被命名为external_sd,您的代码将失败.
control + shift + o - >在eclipse中添加导入,请看这个链接
"/sdcard/" is replace with "Environment.getExternalStorageDirectory().getPath()" in your code
Run Code Online (Sandbox Code Playgroud)
问题是您调用了一个名为Environment.java的文件本身,因此Eclipse没有让我选择导入环境更改那个.
| 归档时间: |
|
| 查看次数: |
25348 次 |
| 最近记录: |