---
title: "java各种情况下读取文件时的路径问题"
author: "fandayrockworld"
date: "2012-01-09T17:14:16Z"
tags: []
categories: ["编程语言"]
slug: "java"
draft: false
lastmod: "2012-01-09T17:17:14Z"
id: 1338905
url: "https://fandayrockworld.iteye.com/blog/1338905"
---

jar包中：

```
BufferedReader br = new BufferedReader(new InputStreamReader(ClassLoader.getSystemResourceAsStream("destination_file")));
```

 

war包中：

 

```
this.getClass().getResource("/").getPath();// war包://WEB-INF/classes目录
this.getClass().getResource("AnyClassOrFile").getPath();// 程序中任意类或文件的路径
```

servlet访问方式不赘。

 

工程中：

不赘述。

 

更详细的可见下列文章：

 

[http://zhidao.baidu.com/question/340516870.html?seed=0](http://zhidao.baidu.com/question/340516870.html?seed=0)

[http://daniel-tu.iteye.com/blog/433414](http://daniel-tu.iteye.com/blog/433414)