---
title: "Restlet2.0学习——文件路径访问"
author: "cosmo1987"
date: "2012-05-22T14:42:05Z"
tags: []
categories: ["企业架构"]
slug: "restlet2-0"
draft: false
lastmod: "2012-05-22T14:42:05Z"
id: 1537463
url: "https://cosmo1987.iteye.com/blog/1537463"
---

由于就是官方的实例照搬了一下，简单尝试没有问题。就先把代码贴出来了。


```java
public class DirStartRun {
	/**
	 * web browser input:http://localhost:8182/
	 * @param args
	 * @throws Exception
	 */
	public static void main(String[] args) throws Exception {
		// URI of the root directory.   
		final String ROOT_URI = "file:///c:/restlet/docs/api/";    
		  
		// Create a component   
		Component component = new Component();   
		component.getServers().add(Protocol.HTTP, 8182);   
		component.getClients().add(Protocol.FILE);   
		  
		// Create an application   
		Application application = new Application() {   
		    @Override  
		    public Restlet createInboundRoot() {   

		    	return new Directory(getContext(), ROOT_URI);   
		    }   
		};   
		  
		// Attach the application to the component and start it   
		component.getDefaultHost().attach(application);   
		component.start();  
	}
	
}
```