将文本文件写入子文件夹 [英] Write a text file to a sub-folder
问题描述
我正在尝试将文本文件写出到:C:\Test folder\output\
,但没有将 C:\
放入.
I am trying to write out a text file to: C:\Test folder\output\
, but without putting C:\
in.
即
这是我目前所拥有的,目前有效,但开头有 C:\
.
This is what I have at the moment, which currently works, but has the C:\
in the beginning.
StreamWriter sw = new StreamWriter(@"C:\Test folder\output\test.txt");
我真的想将文件写入输出文件夹,但不必在前面有 C:\
.
I really want to write the file to the output folder, but with out having to have C:\
in the front.
我尝试了以下方法,但我的程序只是挂起(没有写出文件):
I have tried the following, but my program just hangs (doesn't write the file out):
(@"\\Test folder\output\test.txt");
(@".\Test folder\output\test.txt");
("//Test folder//output//test.txt");
("./Test folder//output//test.txt");
无论如何我能做到这一点吗?
Is there anyway I could do this?
谢谢.
推荐答案
感谢大家的帮助.
我的一位同事也加入并提供了帮助,但@Kami 也提供了很多帮助.
A colleague of mine chipped in and helped as well, but @Kami helped a lot too.
它现在可以工作了:
string path = string.Concat(Environment.CurrentDirectory, @"\Output\test.txt");
正如他所说:CurrentDirectory
是程序运行的地方.
As he said: "The CurrentDirectory
is where the program is run from.
这篇关于将文本文件写入子文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!