using (FileStream filestream = new FileStream("GZIPexample2.txt", FileMode.Open, FileAccess.ReadWrite))
{
using (GZipStream gZipStream = new GZipStream(filestream, CompressionMode.Decompress))
{
long length = filestream.Length;
byte[] arr = new byte[length];
gZipStream.Read(arr,0,(int)length);
//大坑!!!无法确认解压后多大,这数组是解压前的大小,建议直接把这个方法弃用!!!!!!
foreach (var i in arr)
{
Console.WriteLine(i);
}
//using (StreamReader reader = new StreamReader(gZipStream))
//{
// string data = reader.ReadToEnd();
// byte[] byteArray = Encoding.UTF8.GetBytes(data);
// foreach (var i in byteArray)
// {
// Console.WriteLine(i);
// }
//}
//↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑这种方法不好用,建议直接弃用↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
}
}
}
public static void ZIPFileExample()
{
Directory.CreateDirectory("ZIPFileExample");
Directory.CreateDirectory("ZIPFileExampleExtract");
File.WriteAllText("./ZIPFileExample/1.txt","This is a txt file");
ZipFile.CreateFromDirectory("ZIPFileExample","1.zip");
ZipFile.ExtractToDirectory("1.zip", "ZIPFileExampleExtract");
}
public static void SetLengthExample()
{
using (FileStream fileStream = new FileStream("example.txt", FileMode.OpenOrCreate))
{
fileStream.SetLength(70); //包含第70个
//fileStream.Seek();
}
补充下FileWatcher:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace FileWatcherTest
{
public partial class Form1 : Form
{
public static FileSystemWatcher watcher = new FileSystemWatcher();
public static Random rd = new Random();
public Form1()
{
InitializeComponent();
}