gpt4 book ai didi

保存文件的Android FileOutputStream

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:22:41 26 4
gpt4 key购买 nike

这里是我如何将字节写入文件。我正在使用 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();
}
}
}

现在我想打开那个文件,所以我需要有那个文件的路径。那么我需要如何打开该文件?

编辑:

这是我如何从文件中读取,但我什么也看不到...

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();
}

最佳答案

我建议用它来写作:

OutputStream out = new FileOutputStream(Environment.getExternalStorageDirectory().getAbsolutePath()+"/yourfilename");

所以要读取位置:

File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/"+transaction.getUniqueId()+".pdf");

读取路径:

file.getAbsolutePath();

关于保存文件的Android FileOutputStream,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31726311/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com