这里我如何将字节写入文件。我正在使用FileOutputStream
private final Handler handler = new Handler(){
@Override
public void handleMessage(Message msg) {
FragmentActivity activity = getActivity();
byte[] readBuffer = (byte[]) msg.obj;
FileOutputStream out = null;
try {
out = new FileOutputStream("myFile.xml");
out.write(readBuffer);
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在我想打开那个文件,所以我需要有那个文件的路径。那么我需要如何打开该文件?
编辑:
在这里我如何从文件中读取,但我什么也看不到......
BufferedReader reader = null;
FileInputStream s = null;
try {
s = new FileInputStream("mano.xml");
reader = new BufferedReader(new InputStreamReader(s));
String line = reader.readLine();
Log.d(getTag(), line);
while (line != null) {
Log.d(getTag(), line);
line = reader.readLine();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
小智 4
我建议用它来写作:
OutputStream out = new FileOutputStream(Environment.getExternalStorageDirectory().getAbsolutePath()+"/yourfilename");
Run Code Online (Sandbox Code Playgroud)
因此要读取位置:
File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/"+transaction.getUniqueId()+".pdf");
Run Code Online (Sandbox Code Playgroud)
读取路径:
file.getAbsolutePath();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18907 次 |
| 最近记录: |