Unauthorizedaccessexception未得到处理。行fileopen是问题所在。这是一个学校项目。提前谢谢你的帮助! [英] Unauthorizedaccessexception was unhandled. The line fileopen was the problem. This is a school project. Thank you for your help in advance!

查看:93
本文介绍了Unauthorizedaccessexception未得到处理。行fileopen是问题所在。这是一个学校项目。提前谢谢你的帮助!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Option Explicit On
Imports Microsoft.VisualBasic.FileSystem
Module Module1
    Structure ConcertTour
        Dim BandName As String
        Dim noofGigs As Integer
        Dim StartDate As Date
    End Structure
    Dim MyTour As ConcertTour

    Public Sub Main()
        Dim choice As Integer
        FileOpen(1, "C:\ConcertsRandom.DAT", OpenMode.Random)
        Do
            Console.WriteLine(" 1 to create. 2 to Enter. 3 to retrieve.")
            Console.Write("choice? ") : choice = Console.ReadLine
            If choice = 1 Then Call CreateDummyRecords()
            If choice = 2 Then Call EnterRecords()
            If choice = 3 Then Call RetrieveRecords()

        Loop Until choice = 4
        FileClose(1)
        Console.ReadLine()


    End Sub
    Sub CreateDummyRecords()
        Dim i As Integer
        For i = 1 To 30
            MyTour.BandName = "********************"
            MyTour.noofGigs = 0
            MyTour.StartDate = #1/1/2016 12:00:00 PM#
            FilePut(1, MyTour, i)
        Next
        Console.WriteLine()
        Console.WriteLine("dummyfiles created...")
    End Sub

    Sub EnterRecords()
        Dim hashcode As Integer
        Do
            Console.Write(" Band name (xxx to end)? ")
            MyTour.BandName = Console.ReadLine
            If MyTour.BandName <> "xxx" Then
                Console.Write(" no of gigs: ") : MyTour.noofGigs = Console.ReadLine
                Console.Write("start date: ") : MyTour.StartDate = Console.ReadLine
                hashcode = Asc(Left(MyTour.BandName, 1)) - 64
                FilePut(1, MyTour, hashcode)
            End If
        Loop Until MyTour.BandName = "xxx"
    End Sub

    Sub RetrieveRecords()
        Dim hashcode As Integer
        Console.Write(" Band name? ")
        MyTour.BandName = Console.ReadLine
        hashcode = Asc(Left(MyTour.BandName, 1)) - 64
        FilePut(1, MyTour, hashcode)
        Call DisplayRecordData(hashcode)
    End Sub

    Sub DisplayRecordData(ByVal thishashcode As Integer)
        Console.Write(" record key " + Str(thishashcode) + " ")
        Console.Write(MyTour.BandName + " ")
        Console.Write(Str(MyTour.noofGigs) + " ")
        Console.WriteLine(MyTour.StartDate)
    End Sub





End Module





我的尝试:



i尝试更改文件路径,使用不同的导入系统无法正常工作。



What I have tried:

i have tried changing the file path and with different imports system it does not work.

推荐答案

错误消息非常清楚:UnauthorizedAccessExceotion意味着什么 - yo9u试图访问您的代码正在运行的用户的文件或目录,因为没有正确的权限以这种方式访问​​:可能是你没有具有该文件的写入权限,或者您可能无权访问该文件夹。我们无法分辨。



但是......如果真的是你的路径: C:\ConcertsRandom.DAT 那么除了作为管理员之外你不会有写入权限,因为它是你的启动驱动器,根文件夹是写保护的,以防止病毒活动搞乱系统文件。

不存储数据在 任何 驱动器的根目录中,特别是在可启动驱动器的根目录中。



请参阅此处:我应该在哪里存储数据? [ ^ ] - 代码在C#中但这很明显。
The error message is pretty clear: UnauthorizedAccessExceotion means what is says - yo9u tried to access a file or directory that the user your code is running as does not have the right permissions to access in that way: it may be that you don't have Write access to the file, or you may not have any access to the folder. We can't tell.

But ... if that is really your path: C:\ConcertsRandom.DAT then you will not have write access to it except as an admin as it is your boot drive and the root folder is write protected to prevent virus activity messing with system files.
Do not store data in the root of any drive, and especially not in teh root of a bootable drive.

See here: Where should I store my data?[^] - the code is in C# but it's pretty obvious.


这篇关于Unauthorizedaccessexception未得到处理。行fileopen是问题所在。这是一个学校项目。提前谢谢你的帮助!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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