how to read file by ZipFile
2018-02-06 18:10
309 查看
download dll:
icsharpcode.sharpziplib.dll
put it into the directory unity Plugin directory.
write a path tool to get the file directory. this tool we will fill in the future.
now the code is short and not full.
last we will write a demo script the read from zip file. zip file is like this:
C# testing code is :
the entry in the zip can be xml. txt. and others.
will fulfill.
icsharpcode.sharpziplib.dll
put it into the directory unity Plugin directory.
write a path tool to get the file directory. this tool we will fill in the future.
now the code is short and not full.
using System.Collections; using System.Collections.Generic; using UnityEngine; using System; using System.IO; public static class PathUtil { public static string ToForwardSlash(this string path) { return path.Replace(@"\", @"/"); } public static string ToSingleForwardSlash(this string path) { return path.Replace(@"//", @"/"); } public static string ConverRelativePathToEditorOutputPath(string relativePath) { string platformPath = string.Empty; #if UNITY_ANDROID platformPath = "Android/"; #elif UNITY_IOS platformPath = "iOS"; #else platformPath = "Windows"; #endif string outputPath = Path.Combine(Application.dataPath, "../TempData/" + platformPath).ToForwardSlash().ToSingleForwardSlash(); return Path.Combine(outputPath, relativePath.ToSingleForwardSlash().ToForwardSlash()).ToForwardSlash().ToSingleForwardSlash(); } }
last we will write a demo script the read from zip file. zip file is like this:
C# testing code is :
using System.Collections; using System.Collections.Generic; using UnityEngine; using System.IO; using System; using ICSharpCode.SharpZipLib.Zip; public class ZipFileRead : MonoBehaviour { private ZipFile m_zipFile; private void OnGUI() { if(Input.GetKeyDown(KeyCode.A)) { string fileName = "a.zip"; string filePath = PathUtil.ConverRelativePathToEditorOutputPath(fileName); if(File.Exists(filePath)) { byte[] zipBytes = File.ReadAllBytes(filePath); m_zipFile = new ZipFile(new MemoryStream(zipBytes)); } ZipEntry zipEntry = m_zipFile.GetEntry("a.txt"); Debug.Log(zipEntry.Name); } } }
the entry in the zip can be xml. txt. and others.
will fulfill.
相关文章推荐
- How to read file line by line?
- How to read a file line by line?
- nrf51822 secure DFU by OTA: How to Set Password in the DFU zip File
- How to mount partition with ntfs file system and read write access
- How to mount partition with ntfs file system and read write access
- How To Read and Write BLOB Data by Using ADO.NET with Visual C# .NET
- How to read data from csv file in c#
- How To Read A Research Paper?---by Mubarak Shah
- 论 Failed to read zip file 'D:\\app\build\intermediates\transfor\proguard\debug\jars\2\1f\main.jar解决
- Unable to locate JAR/zip in file system as specified by the driver definition: mysql-connector-java-
- HOW TO: Upload a File to a Web Server in ASP.NET by Using Visual Basic .NET
- Why is using BufferedInputStream to read a file byte by byte faster than using FileInputStream
- How to use GCC to build DLL by DEF file in MinGW?
- How to read a PCap file from Wireshark with C++
- Shell Script Utility To Read a File Line By Line
- How to Read, Write XLSX File in Java - Apach POI Example---reference
- How to successfully edit readonly file in VS?
- How to build a COM to Send and Receive Multi File by ATL
- QT24&25 how to run exe file by clicking a button in Qt
- How to save/read file on different platforms