我需要尽快写入许多文件,但我没有按照我使用的方式使用 Streamwriter 获得我想要的结果。例如,如果我写...
$File = "c:\somefile"
$Contents = get-content $File
$Contents | set-content $File
Run Code Online (Sandbox Code Playgroud)
所以读取文件的内容,什么都不做,然后写回来......文件是完全一样的。但是如果我写...
$File = "c:\somefile"
$Contents = get-content $File
$stream = [System.IO.StreamWriter] $File
$stream.WriteLine("$contents")
$stream.close()
Run Code Online (Sandbox Code Playgroud)
然后该文件看起来好像所有换行符都被忽略了,并且有点混乱。我需要做什么才能正确写入?非常感谢!