タイトルはそれをすべて言います:
- 私はtar.gzアーカイブを次のように読みました
- ファイルをバイトの配列に分割する
- それらのバイトをBase64文字列に変換します
- そのBase64文字列をバイトの配列に変換します
- それらのバイトを新しいtar.gzファイルに書き戻します
両方のファイルが同じサイズであることを確認できますが(以下のメソッドはtrueを返します)、コピーバージョンを抽出できなくなりました。
何か不足していますか?
Boolean MyMethod(){
    using (StreamReader sr = new StreamReader("C:\...\file.tar.gz")) {
        String AsString = sr.ReadToEnd();
        byte[] AsBytes = new byte[AsString.Length];
        Buffer.BlockCopy(AsString.ToCharArray(), 0, AsBytes, 0, AsBytes.Length);
        String AsBase64String = Convert.ToBase64String(AsBytes);
        byte[] tempBytes = Convert.FromBase64String(AsBase64String);
        File.WriteAllBytes(@"C:\...\file_copy.tar.gz", tempBytes);
    }
    FileInfo orig = new FileInfo("C:\...\file.tar.gz");
    FileInfo copy = new FileInfo("C:\...\file_copy.tar.gz");
    // Confirm that both original and copy file have the same number of bytes
    return (orig.Length) == (copy.Length);
}編集:作業例ははるかに簡単です(@TSのおかげで):
Boolean MyMethod(){
    byte[] AsBytes = File.ReadAllBytes(@"C:\...\file.tar.gz");
    String AsBase64String = Convert.ToBase64String(AsBytes);
    byte[] tempBytes = Convert.FromBase64String(AsBase64String);
    File.WriteAllBytes(@"C:\...\file_copy.tar.gz", tempBytes);
    FileInfo orig = new FileInfo(@"C:\...\file.tar.gz");
    FileInfo copy = new FileInfo(@"C:\...\file_copy.tar.gz");
    // Confirm that both original and copy file have the same number of bytes
    return (orig.Length) == (copy.Length);
}ありがとう!
                  このように圧縮ファイルの内容を変更することはできません。そのまま直接読み込むのではなく、手順1でファイルを解凍する必要があります。そして、ステップ5も、バイトを直接書き込むだけでなく、データを再圧縮する必要があります。
                
                
                  
                    —
                    itsme86 2014 
                    
                  
                
              
                  幸い、ファイル自体の実際の操作はなかったので(基本的には、ファイルをポイントAからBに移動するだけです)、この特定のタスクでは、(デ/)圧縮は必要ありません
                
                
                  
                    —
                    darkpbj