---
title: "java工程读取本地文件方法"
author: "anlinko"
date: "2022-05-02T13:42:44Z"
tags: ["Java"]
categories: ["编程语言"]
slug: "java"
draft: false
lastmod: "2022-05-02T13:42:44Z"
id: 2530962
url: "https://anlinko.iteye.com/blog/2530962"
---

**读本地工程文件 resources**



```java


 读本地工程文件 resources
当前包下返回上级根目录到 resources
this在utils包下
 File file = new File(this.getClass().getResource("../history.txt").getFile());


 //此处不能选择ico格式的图片,要使用16*16的png格式的图片

读本地工程图片 resources
SearchController 当前类
 BufferedImage image = ImageIO.read(SearchController.class.getClassLoader().getResource("my.png"));


```