Program Examples:File Handling:Open Read Write/zh-hans

From SoftMC-Wiki
Jump to: navigation, search
语言: English  • 中文(简体)‎

以下示例演示如何打开具有不同权限(只读,写入,附录),如何从文件读取和写入文件以及如何操作文件指针的文件。

program

	dim pos as long
	dim d1 as double
	dim s1 as string

	'create file for writing
	Open "test.prg" mode = "w" as #1
	print #1, "1.2345"
	close #1

	'append to existing file
	Open "test.prg" mode = "a" as #1
	print #1, PI
	close #1
	'read from file
	Open "test.prg" mode = "r" as #1

	'how many characters in the file?
	print "File contains ";loc(1);" characters"
	s1 = input$(#1)

	'convert from string to double
	d1=val(s1)
	?d1

	'save current file pointer
	pos = tell(#1)
	print "File pointer Position = ";pos
	?input$(#1)

	'rewind file
	seek (#1,pos)
	?input$(#1)
	close #1

end program


该示例对应于在GIT中的提交的SHA-1: ada143a7f402e6bbad24c13c56401a5393ce3d2b in GIT.


参见