File.WriteAllBytes creating 0 byte files

TommyGunn32

Is it possible for this combination of lines to create a 0 byte file? I would expect the write to always complete. Thanks!

File.WriteAllBytes(file_name, encrypted_data);
encrypted_data = null;

Edit: assuming my byte array isn't empty of course, which I am adding checks for.

basel qyqony

try to user writeByte instead of File.WriteAllBytes

FileStream stream = File.Open(FilePath,FileMode.OpenOrCreate);            
                   if (null != stream)
                   {
                       byte[] encrypted_data=something; // your bytes
                       foreach (byte b in encrypted_data)
                       {
                           stream.WriteByte(b);
                       }
                   }
stream.Close();

you can still use System.IO.File.ReadAllBytes when you read file

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

File.WriteAllBytes가 0 바이트 파일을 생성합니다.

분류에서Dev

How to delete an invincible 0 byte file?

분류에서Dev

Batch File - Creating multiple files with different names

분류에서Dev

Creating XML file that fits certain rules that are in xsl and xslt files?

분류에서Dev

BinaryRead / Write / FileStream.Read/Write /File.Read/WriteAllBytes 후 파일 손상

분류에서Dev

Codenameone getting the byte[] of a file

분류에서Dev

Massively creating files with bash

분류에서Dev

Creating folders and files in Parallel

분류에서Dev

PDFBox to byte array length 0

분류에서Dev

xauth not creating .Xauthority file

분류에서Dev

Sending and creating a File

분류에서Dev

Creating a file in php

분류에서Dev

Creating a make file

분류에서Dev

Open() for output not creating file

분류에서Dev

Creating a function to write to a file

분류에서Dev

Is there a shortcut for creating a new file?

분류에서Dev

excessive creating and deleting files disadvantages

분류에서Dev

Pickle: Reading and creating empty files

분류에서Dev

Creating Unit files in Ubuntu 16.04

분류에서Dev

Writing a file from byte array into a zip file

분류에서Dev

Searching for specific magic byte in an ocean of files

분류에서Dev

Reading partition/directory /storage/extSdCard as a file, byte by byte. Android

분류에서Dev

Creating Setup FIle Using InstallShield

분류에서Dev

Creating Username from Text File

분류에서Dev

Creating a .desktop file for a new application

분류에서Dev

ZipFile module creating .pyc file

분류에서Dev

Escape byte array error, if file not exist

분류에서Dev

How to read a byte from a file in elisp

분류에서Dev

rsync isn't creating files or folders