|
天堂之光 人间希望
你我共同品味
JAVA的浓香.
Linux的清芬. |
« | August 2025 | » | 日 | 一 | 二 | 三 | 四 | 五 | 六 | | | | | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | | | | | | | |
链接 |
联系我
msn:zhanglincon@hotmail.com |
Blog信息 |
blog名称: 日志总数:99 评论数量:281 留言数量:4 访问次数:808325 建立时间:2005年11月17日 |

| |
[java文件操作专题]列出指定目录下的文件 原创空间, 软件技术
zhanglincon 发表于 2008/2/16 14:48:53 |
package book.io;
import java.io.File; import java.io.FilenameFilter;
/** * File类的list方法返回该目录下的所有文件(包括目录)的文件名,文件名不含路径信息 * File类的listFiles方法返回目录下的所有文件(包括目录)的File对象 * FilenameFilter是文件名过滤器接口类,所有自定义的文件名过滤器必须实现该接口的accept方法 * @author Administrator * */ public class ListFileUtil {
/** * 这是一个内部类,实现了FilenameFilter接口,用于过滤文件 */ static class MyFilenameFilter implements FilenameFilter{ |
|
[java文件操作专题]列出文件的属性信息 原创空间, 软件技术
zhanglincon 发表于 2008/2/16 13:15:43 |
package book.io;
import java.io.File; import java.text.DecimalFormat; import java.util.Date;
/** * 获取文件的基本信息 * @author Administrator * */ public class GetFileInfos {
public static void println(String s){ System.out.println(s); } public static void main(String[] args){ //用文件路径创建一个文件对象,文件路径可以是相对路径也可以是绝对路径 File file = new File("c:/tem |
|
[java文件操作专题]在java中使用相对路径找到配置文件 原创空间, 软件技术
zhanglincon 发表于 2008/2/13 12:42:12 |
在开发过程中,我们经常会遇到读取配置文件的情况,对于配置文件的读取,根据环境等情况又各有不同,一般情况下,如果从非jar包中使用相对/路径,比较简单,就不在累述了,而在很多 情况下,我们需要把我们的class打包成jar文件,进行使用,这时就会发现,我们先前如果没有考虑到这些,可能就行不通了,那么,该如何解决呢?方法如下 : 有如下路径 : Web-info--|-->classes--->conf-->config.properties |-->lib 此时加入我们需要读取config.properties,在不使用jar包时,使用如下方式读取,不失为一种方法: File f = new File(this.getClass().getResource("/").getPath()); f = new File(f.getPath() + "/conf/config.properties"); 注:f.getPath()即为当class所在的绝对路径。如:c:\javasrc\we |
|
[java文件操作专题]删除目录和文件 原创空间, 软件技术
zhanglincon 发表于 2008/2/13 12:19:42 |
import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.text.SimpleDateFormat; import java.util.Date;
public class FileOperate {
/** * 创建目录 * @param folderPath:目录路径 * @return * @throws IOException */ public static boolean createFolder(String folderPath) throws IOException{ boolean result = false; File f = new File(folderPath);
if(!f.exists()){ result = |
|
[java文件操作专题]Java文件操作大全 原创空间, 软件技术
zhanglincon 发表于 2008/2/13 12:17:25 |
本文汇集常用文件操作方法,包括文件的建立/检查与删除,目录的建立/检查与删除,取出目录中文件,文件属性的取得,逐行读取数据等等。
文件的建立/检查与删除
<%@ page contentType="text/html;charset=gb2312"%> <%@ page import="java.io.*"%> <html> <head> <title>文件的建立、检查与删除</title> </head> <body> <% String path=request.getRealPath(""); //out.println(path); File f=new File(path,"File.txt"); //out.println(f); //out.println(f.exists());
if |
|
« 1 ›
|