JAVA文件操作类和文件夹的操作Word下载.docx

上传人:b****3 文档编号:15042975 上传时间:2022-10-27 格式:DOCX 页数:7 大小:16.63KB
下载 相关 举报
JAVA文件操作类和文件夹的操作Word下载.docx_第1页
第1页 / 共7页
JAVA文件操作类和文件夹的操作Word下载.docx_第2页
第2页 / 共7页
JAVA文件操作类和文件夹的操作Word下载.docx_第3页
第3页 / 共7页
JAVA文件操作类和文件夹的操作Word下载.docx_第4页
第4页 / 共7页
JAVA文件操作类和文件夹的操作Word下载.docx_第5页
第5页 / 共7页
点击查看更多>>
下载资源
资源描述

JAVA文件操作类和文件夹的操作Word下载.docx

《JAVA文件操作类和文件夹的操作Word下载.docx》由会员分享,可在线阅读,更多相关《JAVA文件操作类和文件夹的操作Word下载.docx(7页珍藏版)》请在冰豆网上搜索。

JAVA文件操作类和文件夹的操作Word下载.docx

class 

FileOperate 

{

private 

String 

message;

FileOperate() 

/**

读取文本文件内容

@param 

filePathAndName 

带有完整绝对路径的文件名

encoding 

文本文件打开的编码方式

@return 

返回文本文件的内容

*/

readTxt(String 

filePathAndName,String 

encoding) 

throws 

IOException{

encoding.trim();

StringBuffer 

str 

new 

StringBuffer("

"

);

st 

;

try{

FileInputStream 

fs 

FileInputStream(filePathAndName);

InputStreamReader 

isr;

if(encoding.equals("

)){

isr 

InputStreamReader(fs);

}else{

InputStreamReader(fs,encoding);

}

BufferedReader 

br 

BufferedReader(isr);

data 

while((data 

br.readLine())!

=null){

str.append(data+"

}catch(Exception 

e){

str.append(e.toString());

str.toString();

}catch(IOException 

es){

return 

st;

新建目录

folderPath 

目录

返回目录创建后的路径

createFolder(String 

folderPath) 

txt 

folderPath;

try 

java.io.File 

myFilePath 

java.io.File(txt);

if 

(!

myFilePath.exists()) 

myFilePath.mkdir();

catch 

(Exception 

e) 

message 

创建目录操作出错"

txt;

多级目录创建

准备要在本级目录下创建新目录的目录路径 

例如 

c:

myf

paths 

无限级目录参数,各级目录以单数线区分 

a|b|c

返回创建文件后的路径 

myfac

createFolders(String 

folderPath, 

paths){

txts 

StringTokenizer 

StringTokenizer(paths,"

|"

for(int 

i=0;

st.hasMoreTokens();

i++){

st.nextToken().trim();

if(txts.lastIndexOf("

/"

)!

=-1){ 

createFolder(txts+txt);

createFolder(txts+txt+"

创建目录操作出错!

txts;

新建文件

文本文件完整绝对路径及文件名

fileContent 

文本文件内容

@return

void 

createFile(String 

filePathAndName, 

fileContent) 

filePath 

filePathAndName;

filePath.toString();

File 

File(filePath);

myFilePath.createNewFile();

FileWriter 

resultFile 

FileWriter(myFilePath);

PrintWriter 

myFile 

PrintWriter(resultFile);

strContent 

fileContent;

myFile.println(strContent);

myFile.close();

resultFile.close();

创建文件操作出错"

有编码方式的文件创建

编码方式 

GBK 

或者 

UTF-8

fileContent, 

PrintWriter(myFilePath,encoding);

删除文件

Boolean 

成功删除返回true遭遇异常返回false

boolean 

delFile(String 

filePathAndName) 

bea 

false;

myDelFile 

if(myDelFile.exists()){

myDelFile.delete();

true;

(filePathAndName+"

删除文件操作出错"

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 求职职场 > 简历

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1