积极答复者
如何生成自定义扩展名的文件?

问题
答案
-
别急,这样试试:
Option Explicit On
Option Strict On
Imports System
Imports System.IO
Class MyStream
Private Const FILE_NAME As String = "Test.jpg"
Public Shared Sub Main()
' Create the new, empty data file.
If File.Exists(FILE_NAME) Then
Console.WriteLine("{0} already exists!", FILE_NAME)
Return
End If
Dim fs As New FileStream(FILE_NAME, FileMode.CreateNew)
' Create the writer for data.
Dim w As New BinaryWriter(fs)
' Write data to Test.data.
Dim i As Integer
For i = 0 To 10
w.Write(CInt(i))
Next i
w.Close()
fs.Close()
' Create the reader for data.
fs = New FileStream(FILE_NAME, FileMode.Open, FileAccess.Read)
Dim r As New BinaryReader(fs)
' Read data from Test.data.
For i = 0 To 10
Console.WriteLine(r.ReadInt32())
Next i
r.Close()
fs.Close()
End Sub
End Class
全部回复
-
Imports System
Imports System.IO
Public Class BinaryRW
Shared Sub Main()
Dim i As Integer = 0
Dim invalidPathChars() As Char = Path.InvalidPathChars
Dim memStream As new MemoryStream()
Dim binWriter As New BinaryWriter(memStream)
' Write to memory.
binWriter.Write("Invalid file path characters are: ")
For i = 0 To invalidPathChars.Length - 1
binWriter.Write(invalidPathChars(i))
Next i
' Create the reader using the same MemoryStream
' as used with the writer.
Dim binReader As New BinaryReader(memStream)
' Set Position to the beginning of the stream.
memStream.Position = 0
' Read the data from memory and write it to the console.
Console.Write(binReader.ReadString())
Dim memoryData( _
CInt(memStream.Length - memStream.Position) - 1) As Char
For i = 0 To memoryData.Length - 1
memoryData(i) = Convert.ToChar(binReader.Read())
Next i
Console.WriteLine(memoryData)
End Sub
End Class -
真是不好意思,没说清楚。对不起。
我的意思是,有一个Form,里面有两个textbox,一个richtextbox,一个PictureBox和可以播放音频的控件。然后我保存这些资料的时候生成一个*.muradil这个样一个文件格式的文件。如果有安装过我自己做的软件的电脑,可以双击刚才保存的文件直接打开,当然打开的时候用我自己做的软件打开。现在肯定知道我的意思了。呵呵。。。太麻烦你了。谢谢你
就像word ,word的扩展名是.doc,我们保存的时候有一个*.doc的文件出现。我们需要的时候双击那个*.doc的文件就能打开你以前保存过的文件。当然这个里面包含很多信息,比如图片文字等。谢谢你。谢谢你这么详细这么认真的讲解。谢谢。。。。
呵呵 。。。。。等你的消息。我的邮箱是muradil0903@126.com
-
想自己定义一个系统可以认出的文件类型吗?很简单,只要在注册表中申请一下就可以。以下示例为创建一个扩展名为"test",默认为记事本打开的文件。
将以下内容放入记事本,保存为"xxx.reg"。注意红色标记部分,应该改成你想要的图标路径!
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\.test]
@="测试文件"[HKEY_CLASSES_ROOT\.test\DefaultIcon]
@="c:\\test.ico"[HKEY_CLASSES_ROOT\.test\OpenWithList]
[HKEY_CLASSES_ROOT\.test\OpenWithList\notepad.exe]
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.test]
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.test\OpenWithList]
"a"="notepad.exe"
"MRUList"="a"[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.test\OpenWithProgids]
"test_auto_file"=hex(0):这是我网上找的。还有:
Imports System
Imports System.IO
Public Class Form1
Sub main1() '检测传进来的参数
Dim cmds As String()
cmds = System.Environment.GetCommandLineArgs
If cmds.Length > 0 Then
Dim i As Integer
For i = 0 To cmds.Length - 1
If cmds(i).ToString Like "*.gulyar" Then '其中abc为你自定义文件的扩展名
cmd = cmds(i).ToString
iscaseurl = True
End If
Next
End If
End SubDim strFileName As String
Dim cmd As String = "" '用来保存传入的参数
Dim iscaseurl As Boolean = False '判断是否是你需要的参数
Dim i As IntegerPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strFileName As String
Dim SaveFileDialog1 As New SaveFileDialog
strFileName = TextBox1.Text
With SaveFileDialog1
.DefaultExt = "byt "
.FileName = strFileName
.Filter = " Textfiles ( *.gulyar )|*.gulyar"
.FilterIndex = 1
.InitialDirectory = "f:\\"
.OverwritePrompt = True
.Title = "文件保存对话框"
End With
'以下是把文本框中的文字另保存为文本文件
If SaveFileDialog1.ShowDialog() = DialogResult.OK Then
strFileName = SaveFileDialog1.FileName
'Create(strFileName)
Dim objWriter As IO.StreamWriter = New IO.StreamWriter(strFileName, False, System.Text.Encoding.Default)
objWriter.Write(TextBox1.Text & Chr(13) & TextBox2.Text & Chr(13) & TextBox3.Text & Chr(13) & RichTextBox1.Text)
objWriter.Close()
objWriter = Nothing
End If
End SubPrivate Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim strFileName As String
Dim openfiledialog1 As New OpenFileDialog
' 设定打开文件对话框的属性
With openfiledialog1
.Filter = "psy( *.gulyar )|*.gulyar"
.InitialDirectory = "f:\\"
.Title = "打开文件对话框"
End With
'以下是打开文本文件,并通过文本框显示出来
If openfiledialog1.ShowDialog() = DialogResult.OK Then
strFileName = openfiledialog1.FileName
Dim objReader As IO.StreamReader = New IO.StreamReader(strFileName, System.Text.Encoding.Default)
TextBox1.Text = objReader.ReadLine
TextBox2.Text = objReader.ReadLine
TextBox3.Text = objReader.ReadLine
RichTextBox1.Text = objReader.ReadToEnd
objReader.Close()
objReader = Nothing
End IfEnd Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call main1()
' reader(cmd)
Dim objReader As IO.StreamReader = New IO.StreamReader(cmd, System.Text.Encoding.Default)
TextBox1.Text = objReader.ReadLine
TextBox2.Text = objReader.ReadLine
TextBox3.Text = objReader.ReadLine
RichTextBox1.Text = objReader.ReadToEnd
objReader.Close()
objReader = Nothing
End Sub
Public Shared Sub Create(ByVal FILE_NAME As String)
' Create the new, empty data file.
If File.Exists(FILE_NAME) Then
' Console.WriteLine("{0} already exists!", FILE_NAME)
MsgBox(FILE_NAME + "已经退出!", , "错误")
Return
End If
Dim fs As New FileStream(FILE_NAME, FileMode.CreateNew)
' Create the writer for data.
Dim w As New BinaryWriter(fs)
' Write data to Test.data.
Dim i As Integer
For i = 0 To 10
w.Write(CInt(i))
Next i
w.Close()
fs.Close()
End Sub
Public Shared Sub reader(ByVal FILE_NAME As String)
' Create the reader for data.
Dim fs As New FileStream(FILE_NAME, FileMode.CreateNew)
fs = New FileStream(FILE_NAME, FileMode.Open, FileAccess.Read)
Dim r As New BinaryReader(fs)
' Read data from Test.data.
Dim i As Integer
For i = 0 To 10
Console.WriteLine(r.ReadInt32())
Next i
r.Close()
fs.Close()
End Sub
End Class
这是我找的。但都是关于文字的东西,没有图片声音之类的。呵呵。。。。。还差一点了。大家帮个忙。谢谢 -
别急,这样试试:
Option Explicit On
Option Strict On
Imports System
Imports System.IO
Class MyStream
Private Const FILE_NAME As String = "Test.jpg"
Public Shared Sub Main()
' Create the new, empty data file.
If File.Exists(FILE_NAME) Then
Console.WriteLine("{0} already exists!", FILE_NAME)
Return
End If
Dim fs As New FileStream(FILE_NAME, FileMode.CreateNew)
' Create the writer for data.
Dim w As New BinaryWriter(fs)
' Write data to Test.data.
Dim i As Integer
For i = 0 To 10
w.Write(CInt(i))
Next i
w.Close()
fs.Close()
' Create the reader for data.
fs = New FileStream(FILE_NAME, FileMode.Open, FileAccess.Read)
Dim r As New BinaryReader(fs)
' Read data from Test.data.
For i = 0 To 10
Console.WriteLine(r.ReadInt32())
Next i
r.Close()
fs.Close()
End Sub
End Class -
将以下内容放入记事本,保存为"xxx.reg"。注意红色标记部分,应该改成你想要的图标路径!
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\.test]
@="测试文件"[HKEY_CLASSES_ROOT\.test\DefaultIcon]
@="c:\\test.ico"[HKEY_CLASSES_ROOT\.test\OpenWithList]
[HKEY_CLASSES_ROOT\.test\OpenWithList\notepad.exe]
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.test]
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.test\OpenWithList]
"a"="xxx.exe"
"MRUList"="a"[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.test\OpenWithProgids]
"test_auto_file"=hex(0):不好意思。太麻烦你了。谢谢
-
真是不好意思,没说清楚。对不起。
我的意思是,有一个Form,里面有两个textbox,一个richtextbox,一个PictureBox和可以播放音频的控件。然后我保存这些资料的时候生成一个*.muradil这个样一个文件格式的文件。如果有安装过我自己做的软件的电脑,可以双击刚才保存的文件直接打开,当然打开的时候用我自己做的软件打开。现在肯定知道我的意思了。呵呵。。。太麻烦你了。谢谢你
就像word ,word的扩展名是.doc,我们保存的时候有一个*.doc的文件出现。我们需要的时候双击那个*.doc的文件就能打开你以前保存过的文件。当然这个里面包含很多信息,比如图片文字等。谢谢你。谢谢你这么详细这么认真的讲解。谢谢。。。。
呵呵 。。。。。等你的消息。我的邮箱是muradil0903@126.com