0

在我的 vb.NET 项目中,我引用了一个名为check_output.txt. 在我打开此文件的代码中,将其写入,然后在默认文本编辑器中显示该文件。我使用的代码是这样的:

Dim FILE_NAME As String = Application.StartupPath & "\" & "check_output.txt"

If System.IO.File.Exists(FILE_NAME) = True Then

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

    objWriter.Write(txtOutput.Text)
    objWriter.Close()

    System.Diagnostics.Process.Start(FILE_NAME)
Else

    MsgBox("Impossibile trovare il file di testo di default", vbCritical, "Errore")

End If

我想把txt文件当作一个临时文件,所以它总是空的,除非我写进去。但我不想让用户在其中保存,所以当他关闭文件时,应该会出现“另存为”对话框。关闭后文件应返回空。这很难获得吗?我怎样才能做到这一点?

换句话说,我希望编辑器在您执行“文件->新建”时充当...所以您有一个临时文件,而不是存储在硬盘中。

4

1 回答 1

1
  1. Write your data to the file and save it.
  2. Change the properties of the file to "Read-Only" (this will disallow "Save" in most editors and only allow "Save As".
  3. After the user completes their work (or closes the application, or whatever), reset the file properties and clear the file.
于 2012-10-31T13:38:49.857 回答