标签: file-access

如何检查是否拒绝访问字符串路径?

我想知道如何测试我是否可以访问字符串路径.这是我使用的代码:

using System;
using System.IO;

namescpace prog1
{
    class Program
    {
        static void Main(string[] args)
        {
            string path = @"C:\Users\Admin";
            DirectoryInfo dir = new DirectoryInfo(path);
            foreach (FileInfo fil in dir.GetFiles())
            {
                //At dir.GetFiles, I get an error  saying
                //access to the string path is denied.

                Console.WriteLine(fil.Name);
            }
            Console.ReadLine();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我想测试访问是否被拒绝(到字符串路径)然后执行GetFiles和所有这些.

我已经发现了这个问题:如何轻松检查.NET中的文件是否被拒绝访问?

有帮助吗?

c# file-access

1
推荐指数
1
解决办法
3694
查看次数

索引文件错误

我正在尝试打开一个索引的文件,但不断收到以下错误.从我能找到的所有COBOL代码示例中,我无法看到我的错误在哪里.

我能够按顺序打开文件就好了.它似乎是试图打开索引的东西.

错误:

project2.cbl:119: libcob: Permanent file error (STATUS = 30) File : 'customers.dat'
Run Code Online (Sandbox Code Playgroud)

系统:

OS X

GnuCOBOL

OpenCobolIDE
Version: 4.7.3
Run Code Online (Sandbox Code Playgroud)

码:

   IDENTIFICATION DIVISION.
   PROGRAM-ID. PROJECT-2.

   ENVIRONMENT DIVISION.
   INPUT-OUTPUT SECTION.
   FILE-CONTROL.

       SELECT CUST-FILE ASSIGN TO "customers.dat"
           ORGANIZATION IS INDEXED
           ACCESS IS RANDOM
           RECORD KEY IS CUST-ID.

       SELECT INV-FILE ASSIGN TO "inventory.dat"
           ORGANIZATION IS INDEXED
           ACCESS IS RANDOM
           RECORD KEY IS ITEM-ID.

       SELECT TRANS-FILE ASSIGN TO "transactions.dat"
           ORGANIZATION IS LINE SEQUENTIAL.

       SELECT SORTED-TRANS-FILE ASSIGN TO "sorted-transactions.dat"
           ORGANIZATION IS LINE SEQUENTIAL.

       SELECT …
Run Code Online (Sandbox Code Playgroud)

cobol indexed file-access gnucobol

1
推荐指数
1
解决办法
756
查看次数

如何在 Rust 中执行线程安全 IO 和缓存到文件?

语境:

我正在编写一个网络服务器,我们在其中处理不同的段。我想将这些不同的段缓存在不同的文件中(段的大小最大可达 10MB)。像这样的东西:

pub async fn segment_handler(segment: String) {
   if is_cached(&segment) {
       return get_from_cache(segment)
   }
   // Do some computation to get the result.
   let result = do_some_large_computation(segment);
   // Cache this result to a file.
   let file_name = &format!("./cache/{}", &segment);
   fs::create(file_name);
   fs::write(file_name, result).expect("Unable to write file");
   result
}
Run Code Online (Sandbox Code Playgroud)

既然segment_handler可以被不同的多个线程调用segment,那么fs::write线程安全吗?如果没有,我们就不能使用互斥体,因为segment: String每次调用的互斥体可能不同,并且使用互斥体会使性能变差。我需要类似互斥体的东西,但仅需要segment: String。这个问题的解决办法是什么?

环境:

  • 铁锈:1.47
  • 网络服务器:扭曲
  • 代码用于:使用 ffmpeg 的 HLS 流
  • 仓库: https: //github.com/blmhemu/rumble(缓存尚未实现)

io concurrency file-access rust

1
推荐指数
1
解决办法
2082
查看次数

在云代工厂的grails应用程序中存储和显示图像文件

我有一个grails应用程序,它允许用户上传图像文件,并可以显示这些图像.应用程序实际上只将文件路径存储在数据库中,并将图像文件保存在文件系统中.

我读过一些帖子,说Cloud Foundry不支持本地文件系统访问.所以我的问题是,如果我想将我的应用程序部署到Cloud Foudry,我应该做哪些修改?我希望图像仍然可以直接显示在网页上,用户不必将它们下载到自己的计算机上进行查看.

grails file-access cloud-foundry image-file

0
推荐指数
1
解决办法
598
查看次数