Disk space StreamWriter vs Out-File

When writing to a text file with .Net StreamWriter, Why does the text file take up less room on disk than when using PowerShell's Out-File. The following script creates the same text file with both StreamWriter and Out-File. But looking at the two text files produced, the 'StreamWriter' text file takes up half the room; why is this?

$String = 1..1000

# StreamWriter
$stream5 = [System.IO.StreamWriter] "E:\\Stream.txt"
$String | %{$stream5.WriteLine($_)}

# Out-File
$string | Out-File "E:\Out-file.txt"


Out-File defaults to Unicode encoding. StreamWriter defaults to UTF8 which uses half the space for common western characters.

I guess the designers of Out-File made a mistake here and picked an unhelpful default. UTF8 is unicode just like UTF-16 is. Just smaller in many common cases. No functional difference.

Need Your Help

Hierarchical Rad Grid Troubles

asp.net telerik radgrid

I'm not sure if anyone else has had trouble with this. I'm trying to use a RAD Grid to create a 4-level hierarchy to display to the user. I followed the tutorial on this website, and couldn't get...

Extended Toolkit WPF DateTimePicker Seconds precision

wpf datetimepicker toolkit

I am using the WPF Extended Toolkit's DateTimePicker. However, when I open the calendar to pick a date, it is only possible to spin hour and minutes. The seconds can only be changed when the calend...