![](/img/trans.png)
[英]How can I write TXT files to "/storage/emulated/0/myapp/myfile.txt" so I can open them from file browser later?
[英]How to Create a file myfile.txt under some aribtrary directories and tar them in Java
我需要创建一个tar文件,该文件下面会有目录和文件。 例:
while(itr.hasNext()) {
String dir = itr.next();
File f = new File("/tmp/apps/"+dir);
f.getParentFile().mkdirs();
File contentFile = new File(f, "myfile.txt");
if(!contentFile.exists()) {
contentFile.createNewFile();
}
Writer out = new FileWriter(contentFile);
BufferedWriter bw = new BufferedWriter(out);
bw.write(someString);
bw.close();
}
//tar the content from /tmp/apps as apps.tar which sould have some directories
and files
JDK本身没有什么对您有帮助。 我建议您添加对Apache Commons-Compress( http://commons.apache.org/compress/ )的依赖。
请参阅文档中的TarArchiveOutputStream和TarArchiveEntry: http ://commons.apache.org/compress/examples.html#tar
有帮助吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.