日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

java访问本地文件_java 读取本地文件 更改

發布時間:2025/3/12 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java访问本地文件_java 读取本地文件 更改 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

/*** @Title: MakeHtml

* @Description: 創建html

*@paramfilePath 設定模板文件

*@paramconent 替換的內容

*@paramdisrPath 生成html的存放路徑

*@paramfileName 生成html名字

*@returnvoid 返回類型

*@throws

*/

public static voidMakeHtml(String filePath,String conent,String disrPath,String fileName ){

InputStreamReader bis= null;try{

System.out.print(filePath);

String templateContent= "";

FileInputStream fileinputstream= new FileInputStream(filePath);//讀取模板文件

StringBuffer sb = newStringBuffer();

bis= new InputStreamReader(fileinputstream,"UTF-8");

BufferedReader br= newBufferedReader(bis);int i=0;while((i=br.read())!=-1){

sb.append((char)i);

}

templateContent=sb.toString();

templateContent= templateContent.replaceAll("模板內容", conent);

String fileame= fileName + ".html";

fileame= disrPath+"/" + fileame;//生成的html文件保存路徑。

FileOutputStream fileoutputstream = new FileOutputStream(fileame);//建立文件輸出流

System.out.print("文件輸出路徑:");

System.out.print(fileame);/*byte tag_bytes[] = templateContent.getBytes();

fileoutputstream.write(tag_bytes);

fileoutputstream.close();*/OutputStreamWriter osw= new OutputStreamWriter(fileoutputstream,"UTF-8");

BufferedWriter bw=newBufferedWriter(osw);/*int j=0;

while((j=br.read())!=-1){

bw.write(j);

}*/bw.write(templateContent);

bw.close();

}catch(Exception e) {

System.out.print(e.toString());

e.printStackTrace();

}finally{try{

bis.close();

}catch(IOException e) {

e.printStackTrace();

}

}

}

總結

以上是生活随笔為你收集整理的java访问本地文件_java 读取本地文件 更改的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。