---
title: "Java Web 开发常用函数"
author: "oxidy"
date: "2008-10-13T10:10:38Z"
tags: []
slug: "java-web"
draft: false
lastmod: "2008-12-19T16:08:38Z"
id: 252027
url: "https://oxidy.iteye.com/blog/252027"
---

```
String s = 'abcdef';
s.substring(0,2);

输出结果为：'abc'

substring(开始，结束)  从第几个字符开始截取，截取到第几个字符
```

 

```
String.valueOf(需要转换的字符、数字等)

转换结果为，括号中的值转换为字符串格式了
```

 

```
比较相等：

数字比较：

1== 1

字符串比较：

"1".equals(字符串)
```

 

```
File   file=new   File(file   path);  
file.isDirectory();//是否目录
```

 

```
File   file   =   new   File(filepath);  
file.exists();//目录或文件是否存在
```

 

```
request.getContextPath();//应用上下文目录，
         获取的也是虚拟路径带/的例如：http:/localhost:8080/hlj_province,获取的是/hlj_province部分
request.getRealPath("dir");//真实路径
```

 

```
//字符String转化为数字int

int i = Integer.parseInt(string)
```

 

随着项目进展，陆续更新