积极答复者
在文件夹下创建文件问题

问题
-
我想点击按钮创建一个文件夹,然后在这个文件夹下继续创建一个同名的TXT文件,结果创建txt时说路径不存在,怎么解决?是不是因为这个文件夹刚创建好,程序运行期间找不到呢?
- 已更改类型 YiChun Chen 2009年6月18日 10:23
答案
-
createfile.create(path & " \ " & name & " \ " & name & ".txt")
多了空格
createfile.create(path & "\" & name & "\" & name & ".txt")
http://feiyun0112.cnblogs.com/- 已标记为答案 YiChun Chen 2009年6月18日 10:23
全部回复
-
-
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim createdir As New mydirectory
Dim name As String = TextBox1.Text
Dim createfile As New myfile
Dim write As New IO.FileStream(path & "\treenodes.txt", FileMode.Append, FileAccess.Write)
Dim contents As String = name & vbCrLf
Dim array() As Byte = System.Text.Encoding.Default.GetBytes(contents.ToCharArray)
If TextBox1.Text = "" Then
MsgBox("请输入目录")
Else
createdir.create(path & "\" & name)
createfile.create(path & " \ " & name & " \ " & name & ".txt")
write.Write(array, 0, array.Length)
write.Close()
TreeView1.Nodes(0).Nodes.Add(name)End If
End Sub
下划线部分没执行,咋回事 -
-
createfile.create(path & " \ " & name & " \ " & name & ".txt")
多了空格
createfile.create(path & "\" & name & "\" & name & ".txt")
http://feiyun0112.cnblogs.com/- 已标记为答案 YiChun Chen 2009年6月18日 10:23