0

I'm creating a text file at executablePath location.

 Path.GetDirectoryName(Application.ExecutablePath) + "\\Paths.txt";

The application works perfectly fine, but for some weird reason when I check the executable directory, the text file is not there.

I have a feeling that it creates the file at some other location, but I can't seem to find it.

I'm creating the file like this;

string PathsDirectory =Path.GetDirectoryName(Application.ExecutablePath)+"\\Paths.txt";
TextWriter tw = new StreamWriter(PathsDirectory);
tw.WriteLine(Data);
tw.Close();

And reading it like this;

string PathsDirectory =Path.GetDirectoryName(Application.ExecutablePath)+"\\Paths.txt";
TextReader tr = new StreamReader(PathsDirectory);
string line;
while ((line = tr.ReadLine()) != null)
{
}

I checked the path after concat and everything looks fine except I can't see the file there.

Ok finally I found the file it's inside;

C:\Users\Alican\AppData\Local\VirtualStore\Program Files (x86)\MyMovies\MyMovies

insted of

C:\Program Files (x86)\MyMovies\MyMovies

4

3 に答える 3

0

私はこれを試してみましたが、私のコンピューターで動作しました:

string filePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\path.txt";
TextWriter tw = new StreamWriter(filePath);
tw.WriteLine("How are you?");
tw.Close();
Console.WriteLine(filePath);

ディレクトリの中を調べたところ、ファイルはすぐそこにあり、私が書いたフレーズが含まれています。

c:\CDash\tests\path\path\bin\Debug\path.txt
于 2013-07-24T21:41:40.100 に答える