【发布时间】:2013-12-13 22:35:57
【问题描述】:
我正在编写一个创建一些文本文件的应用程序。我希望它们在一些文件夹中,所以我这样做了:
Dim fileLoc As String = "c:\users\%username%\downloads\users.txt"
If 1 + 1 = 2 Then <--- not very professional but it works! it works....
Dim fs As FileStream = Nothing
If (Not File.Exists(fileLoc)) Then
fs = File.Create(fileLoc)
Using fs
End Using
End If
End If
If File.Exists(fileLoc) Then
Using sw As StreamWriter = New StreamWriter(fileLoc)
sw.Write(pcname.Text)
End Using
End If
但是当我尝试调试时,会发生以下情况:
DirectoryNotFoundException 未处理 找不到部分路径(c:\users\%username%\downloads\users.txt)
我确定这是因为“%username%”,因为当我填写整个路径时,它可以工作。 但是当程序在另一台电脑上时它就不能工作了!
【问题讨论】:
-
你有用户名吗?
-
出于好奇 - 为什么是
If 1 + 1 = 2? -
lol 也许可以忽略 1+1 = 2(它总是等于 true)并删除 if 语句(以节省更多代码行!)。
-
这是因为我想在 form_load 中运行它,而不是在有人开始操作时运行它