91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

資源簡介

java利用io技術創建文件夾、讀取txt文件、寫入txt文件(覆蓋、不覆蓋均有)

資源截圖

代碼片段和文件信息

package?com.test.util;

import?java.io.BufferedReader;
import?java.io.BufferedWriter;
import?java.io.File;
import?java.io.FileReader;
import?java.io.FileWriter;
import?java.io.IOException;

public?class?FileUtil?{

/**
?*?讀取txt
?*?@param?path(絕對路徑包含文件名)
?*?@return
?*?@throws?IOException
?*/
public?static?String?readtxt(String?path)?throws?IOException{
BufferedReader?br?=?new?BufferedReader(new?FileReader(path));
String?str?=?““;
String?r?=?br.readLine();
while(r!=null){
str?=?str?+?r;
}
br.close();
return?str;
}

/**
?*?寫成txt(不覆蓋)
?*?@param?content
?*?@param?path(絕對路徑包含文件名)
?*?@return
?*?@throws?IOException?
?*/
public?static?void?writetxt(String?contentString?path)?throws?IOException{
FileUtil.createfile(path);
BufferedWriter?bw?=?new?BufferedWriter(new?FileWriter(new?File(path)true));
bw.write(“\r\n“+content);
bw.close();
}

/**
?*?寫成txt(覆蓋)
?*?@param?content
?*?@param?path(絕對路徑包含文件名)
?*?@return
?*?@throws?IOException?
?*/
public?static?void?writetxt2(String?contentString?path)?throws?IOException{
FileUtil.createfile(path);
BufferedWriter?bw?=?new?BufferedWriter(new?FileWriter(new?File(path)));
bw.write(content);
bw.close();
}

/**
?*?創建文件(存在不處理,不存在創建)
?*?@param?path(絕對路徑包含文件名)
?*?@param?args
?*?@throws?IOException?
?*/
public?static?void?createfile(String?path)?throws?IOException{
File?file?=?new?File(path);
if(!file.exists()){
FileUtil.createparentfile(path);
file.createNewFile();
}
}

/**
?*?創建文件夾(存在不處理,不存在創建)
?*?@param?path(絕對路徑包含文件名)
?*?@param?args
?*?@throws?IOException?
?*/
public?static?void?createparentfile(String?path)?throws?IOException{
File?file?=?new?File(path);
File?pfile?=?file.getParentFile();
if(!pfile.exists()){
pfile.mkdirs();
}
}

/**
?*?創建文件夾(存在不處理,不存在創建)
?*?@param?path(絕對路徑包含文件名)
?*?@param?args
?*?@throws?IOException?
?*/
public?static?void?createparentfolder(String?path)?throws?IOException{
File?file?=?new?File(path);
File?pfile?=?file.getParentFile();
if(!pfile.exists()){
pfile.mkdirs();
}
}

/**
?*?創建文件夾(存在不處理,不存在創建)
?*?@param?path(絕對路徑不包含文件名)
?*?@param?args
?*?@throws?IOException?
?*/
public?static?void?createfolder(String?path)?throws?IOException{
File?file?=?new?File(path);
if(!file.exists()){
file.mkdirs();
}
}

public?static?void?main(String[]?args)?{
String?content?=?“11111111111“;
String?path?=?“d://txt//1111.txt“;
try?{
FileUtil.writetxt2(content?path);
}?catch?(IOException?e)?{
//?TODO?Auto-generated?catch?block
e.printStackTrace();
}
}
}

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????2982??2016-06-16?11:42??FileUtil.java

評論

共有 條評論