写入文本文件 [英] write into text file

查看:105
本文介绍了写入文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个写入文本文件的函数,该函数运行没有任何错误,但是当我检查文本时我发现没有任何反应,文件是空的。



当我想写分区C时出现问题,我尝试D它的工作,但为什么?



--->>

I have a function that write into text file,the function run without any error, but when i check the text i see that nothing happens, the file is empty.

the Problem appear when i want to write to partition "C",i tried on "D" it's work, but why ?

--->>

Sub WritePass(ByVal _FilePath As String, ByVal _Pass As String)
        Try
            If System.IO.File.Exists(_FilePath) = True Then

                Dim objWriter As New System.IO.StreamWriter(_FilePath)

                objWriter.Write(_Pass)
                objWriter.Close()
                MsgBox("Text written to file")


            Else

                MsgBox("File Does Not Exist")

            End If
        Catch ex As Exception
        End Try

    End Sub

推荐答案

这是因为分区C有一些安全性。



未经许可,您无法读取,写入文件。
That is because partition "C" has some Security.

You can't read, write to a file without permission.


您是否可以尝试写入C:驱动器的根目录?

在现代MS OS上,访问系统驱动器的根是受限制的。



我们可以知道调用方法时 _FilePath 的值是什么?
Could it be possible you are trying to write at the root of your C: drive ?
On modern MS OS's, access to the system drive's root is restricted.

May we know the value of your _FilePath at the time you are calling your method ?


这篇关于写入文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆