How does one unpack a tar file in Android?

守給你的承諾、 提交于 2020-01-23 01:05:14

问题


I'm not overly familiar with tar, so, this may be a stupid question, but I have a situation where I want to grab a tarball from the server (preferably compressed, but that's not essential), download it on to the device and untar it.

I'm not seeing any standard library to do this... am I overlooking it, or does it not exist?

[EDIT] I'm attempting to do this in my app by means of some API or library that handles unpacking tars - I'm not looking for an app that un-tars stuff on my device.


回答1:


I don't know if there is support for it built into the OS. But you should be able to use a third party library to do it.

Here is one, I am sure there are others to choose from out there as well.




回答2:


Noting down another option here,

Library Name : Apache Commons Compress Apache License, Version 2.0

The Apache Commons Compress library defines an API for working with ar, cpio, Unix dump, tar, zip, gzip, XZ, Pack200, bzip2, 7z, arj, lzma, snappy, DEFLATE, lz4, Brotli, Zstandard, DEFLATE64 and Z files.

Example here: Java TAR example – compress and decompress *.tar or *.tar.gz files This demonstrates how to compress files or directories recursively in .tar or .tar.gz format and how to decompress a .tar or .tar.gz file




回答3:


Sorry for reviving an old question.

As of 6.0/Marshmallow, Android includes Toybox, an executable that contains small versions of every utility.

So on 6+ versions of Android, you can execute tar command as you would on a normal linux system.

As of Q1 2019, 6.0 and higher represent approximately 90% of Android users, so this is more or less safe to do unless you want full support, or are targeting a market with different Android adoption rates.



来源:https://stackoverflow.com/questions/14555278/how-does-one-unpack-a-tar-file-in-android

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!