c# - Determining size of a future file while data is still in memory -


This C # / NET 2.0 is

So I have a string in which the contents of the future are included XML file contains metadata and binary data from image files

I have tried the following or did not work:

 

  console.aut. Written line ("Size:" + data length / 1024 + "KB");  

and

  console.aut. Write line ("size:" + (data length * size (four)) / 1024 + "KB");  

Neither works (as a result the actual size of the file is returned by any of these methods). Any help I'm clearly missing here is to be appreciated.

XML serialization:

  // doc is an XMLDocument that I have previously created stringworld SW = new StringWriter (); Doc.Save (sw); String XMLAsString = sw.ToString ();  

Writing in the file system (XMLAsString variable passed this function as the named data):

  random rnd = new random (dateTime.Now.Millisecond ); Filestream fs = file. Open (@ "C: \ Testout" + rnd.Next (1000) ostring () + ".txt", FileMode.OpenOrCreate); Serial SW = new streamer (FS); App.Diagnostics.Write ("XML Size:" + (Data Length * Size (Characters)) / 1024 + "KB"); Sw.Write (data); Sw.Close (); Fs.Close ();  

thanks

You are missing out on how the encoding process works is . Try it out:

  string data = "this is what I'm typing"; Byte [mybytes = System.Text.Encoding.UTF8.GetBytes (data);  

The size of the array is exactly the number of bytes taken on the disk, if it is being written in some "normal" way, because the UTF 8 is the default encoding for the text output (I think is).

EDIT: I think everyone should remember that there are letters in C # /. The net is not a byte long, but there are two, and unicode characters, which are then encoded which require the output format. This is the reason that any approach with data Length * size (character) will not work


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -