国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Java中對文件的操作

2019-11-18 14:29:37
字體:
來源:轉載
供稿:網友

  java中對文件的操作


java中提供了io類庫,可以輕松的用java實現對文件的各種操作。下面就來說一下如何用java來實現這些操作。


1。新建目錄


<%@ page contentType="text/Html;charset=gb2312"%>

<%

String filePath="c:/aaa/";

filePath=filePath.toString();//中文轉換

java.io.File myFilePath=new java.io.File(filePath);

if(!myFilePath.exists())

myFilePath.mkdir();

%>


2。新建文件


<%@ page contentType="text/HTML;charset=gb2312"%>

<%@ page import="java.io.*" %>

<%

String filePath="c:/哈哈.txt";

filePath=filePath.toString();

File myFilePath=new File(filePath);

if(!myFilePath.exists())

myFilePath.createNewFile();

FileWriter resultFile=new FileWriter(myFilePath);

PRintWriter myFile=new PrintWriter(resultFile);

String strContent = "中文測試".toString();

myFile.println(strContent);

resultFile.close();

%>


3。刪除文件


<%@ page contentType="text/HTML;charset=gb2312"%>

<%

String filePath="c:/支出證實單.xls";

filePath=filePath.toString();

java.io.File myDelFile=new java.io.File(filePath);

myDelFile.delete();

%>


4。文件拷貝


<%@ page contentType="text/HTML; charset=gb2312" %>

<%@ page import="java.io.*" %>

<%

int bytesum=0;

int byteread=0;

file://讀到流中

InputStream inStream=new FileInputStream("c:/aaa.doc");

FileOutputStream fs=new FileOutputStream( "d:/aaa.doc");byte[] buffer =new byte[1444];

int length;

while ((byteread=inStream.read(buffer))!=-1)

{

out.println("<DT><B>"+byteread+"</B></DT>");

bytesum+=byteread;

System.out.println(bytesum);

fs.write(buffer,0,byteread);

}

inStream.close();

%>


5。整個文件夾拷貝


<%@ page contentType="text/HTML;charset=gb2312"%>

<%@ page import="java.io.*" %>

<%String url1="C:/aaa";

String url2="d:/java/";

(new File(url2)).mkdirs();

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 河南省| 嘉黎县| 环江| 文水县| 常宁市| 如皋市| 江北区| 常德市| 华池县| 建平县| 连南| 舒兰市| 荃湾区| 灵武市| 乌恰县| 汉沽区| 饶阳县| 昌吉市| 衡东县| 宕昌县| 绥棱县| 龙里县| 大名县| 双辽市| 东明县| 错那县| 洪泽县| 孟州市| 盖州市| 准格尔旗| 方城县| 汾西县| 延寿县| 汝州市| 桓台县| 石门县| 江北区| 雷波县| 筠连县| 香格里拉县| 囊谦县|