---
title: "java获取项目物理路径"
author: "sunwch"
date: "2010-11-10T15:12:07Z"
tags: ["Java", "Linux", "Windows"]
categories: ["编程语言"]
slug: "java"
draft: false
lastmod: "2010-11-10T15:12:07Z"
id: 807656
url: "https://sunwch.iteye.com/blog/807656"
---

```java

测试只在windows底下，基于Linux没测试..
private String getContextPath(){
		String contextPath = this.getClass().getResource("/").toString().replace("/", "\\\\");
		contextPath = contextPath.substring(contextPath.indexOf("\\")+2,contextPath.length());
		return contextPath;
	}

```