In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains the "Android how to read the zip package directly without decompression", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "Android how to read the zip package without decompression directly"!
Text:
Zip package directory structure: res/txt/data.json
File SD card path: android.os.Environment.getExternalStorageDirectory () + "/ res.zip"
File name of public static String readDataFile (String file) throws Exception {/ / intercept path res String fileName = file.substring (file.length ()-9, file.length ()-4); ZipFile zf = new ZipFile (file); InputStream in = new BufferedInputStream (new FileInputStream (file)); ZipInputStream zin = new ZipInputStream (in); ZipEntry ze While ((ze = zin.getNextEntry ())! = null) {if (ze.isDirectory ()) {/ / Do nothing} else {if (ze.getName (). Equals (fileName + "/ txt/data.json")) {BufferedReader br = new BufferedReader (new InputStreamReader (zf.getInputStream (ze); String line; while ((line = br.readLine ())! = null) {return line;} br.close () } zin.closeEntry (); return "";}
The above method is relatively simple and there is nothing to say, as long as you understand it. One thing you need to pay attention to is that when judging whether you want to read the file, the path here is to compare the compressed directory of zip as the root directory. That is, the current value of fileName in the sentence if (ze.getName (). Equals (fileName + "/ txt/data.json")) is res. Finally, the content read is returned and the String is done.
The reading of the picture and the xml file are similar, and the code is pasted directly below.
Picture:
Zip package directory structure: res/pic/.png
File SD card path: android.os.Environment.getExternalStorageDirectory () + "/ res.zip"
Public static Bitmap readGuidePic (String file, String ResId) throws Exception {String fileName = file.substring (file.length ()-9, file.length ()-4); ZipFile zf = new ZipFile (file); InputStream in = new BufferedInputStream (new FileInputStream (file)); ZipInputStream zin = new ZipInputStream (in); ZipEntry ze While ((ze = zin.getNextEntry ())! = null) {if (ze.isDirectory ()) {/ / Do nothing} else {Log.i ("tag", "file -" + ze.getName () + ":" + ze.getSize () + "bytes"); if (ze.getName (). Equals (fileName + "/ pic/.png")) {InputStream is = zf.getInputStream (ze); Bitmap bitmap = BitmapFactory.decodeStream (is) Return bitmap;}} zin.closeEntry (); return null;}
Xml file:
Zip package directory structure: res/xml/app.xml
File SD card path: android.os.Environment.getExternalStorageDirectory () + "/ res.zip"
Public static InputStream readAppFile (String file) throws IOException {String fileName = file.substring (file.length ()-9, file.length ()-4); ZipFile zf = new ZipFile (file); InputStream in = new BufferedInputStream (new FileInputStream (file)); ZipInputStream zin = new ZipInputStream (in); ZipEntry ze While ((ze = zin.getNextEntry ())! = null) {if (ze.isDirectory ()) {/ / Do nothing} else {if (ze.getName (). Equals (fileName + "/ xml/app.xml")) {InputStream inputStream = zf.getInputStream (ze); return inputStream;}} zin.closeEntry (); return null } Thank you for your reading. The above is the content of "how to read the zip package directly without decompressing Android". After the study of this article, I believe you have a deeper understanding of how Android can read the zip package without decompression, and the specific usage needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.