> For the complete documentation index, see [llms.txt](https://yangsx95.gitbook.io/notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://yangsx95.gitbook.io/notes/computer-science/ji-suan-ji-wang-luo/http/file-xie-yi.md).

# file协议

今天在写spring包扫描实现的时候，要扫描包下的所有class文件。然后我要根据classpath创建一个绝对路径的File对象，所以想到了File的`new File(new URI("file:///path"))`构造。中间遇到了一些坑，特意去了解了一下 `file:///`这个协议。

file协议中文名称为**本地文件协议，通常用于**访问计算机中的本地文件\*\*。我们可以通过向浏览器或者文件管理器输入协议，来查看磁盘中的文件：

![pasted-0](/files/HxMwSZ9XInpIY0UVk8CF)

因为file协议本身是一种协议，所以，它也遵循uri规则：

```
scheme:[//[user:password@]host[:port]][/]path[?query][#fragment]
```

因为host部分不存在，所以，file协议的uri可以写为：

```
file:/path  #准确，此标准称作CURIE， 如果‘/’去除，代表相对路径
或者 
file:///path
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://yangsx95.gitbook.io/notes/computer-science/ji-suan-ji-wang-luo/http/file-xie-yi.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
