java - Android-Java 检测 Output-Stream 何时完成写入字节
问题描述
我的代码工作正常,我只想在写入字节完成后展示一些吐司。我知道当我在 while 循环之后完成读取文件时可以添加 toast in.read(buf) == 0
,因此 while 循环完成。我可以在一段时间后或在关闭您的流之后显示吐司。当我在 while 循环的末尾添加 toast 时,文件显示的时间与显示的 toast 的时间不同。它会在几分钟后显示出来。我怎么知道写入字节已完成或close()
告诉它已完成?
File newfile;
FileInputStream in = new FileInputStream(new File(path));
String root = Environment.getExternalStorageDirectory().getAbsolutePath();
File dir = new File(root + "/" + "Pictures");
if (!dir.exists()) {
dir.mkdirs();
}
newfile = new File(dir, "status_" + System.currentTimeMillis() + ".mp4");
if (newfile.exists()) newfile.delete();
OutputStream out = new FileOutputStream(newfile);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
解决方案
他们是没有办法追踪OutputStream已经写完字节的,只是你可以在之后添加toast什么close()
的。
推荐阅读
- c# - 为什么当其他用户打开我的解决方案时,Visual Studio 2017 会更改用户控件的大小?
- couchdb - 管理具有不同权限的数据库之间的同步
- sql - 如何进行交易管理
- function - 如何在 Fortran 中定义周期函数?
- python - python argparse 在一个命令行中有多个子解析器
- networking - python influxdb用什么网络协议来发送数据?
- swift - 当 ClassA 发生变化时,如何在 ClassB 上执行函数?
- javascript - 如何为 fullcalendar (v5) 事件设置属性?
- ios - 多个目标匹配链接器标志的隐式依赖关系
- reference - 在 Juris-M 中使用 jm-chinese-gb7714-2005-numeric.csl 重复标题