亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫(kù)
最近訪問(wèn)板塊 發(fā)新帖
查看: 2151 | 回復(fù): 0
打印 上一主題 下一主題

java寫入文本文件代碼 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2011-12-23 03:29 |只看該作者 |倒序?yàn)g覽
java寫入文本文件代碼
From:http://www.homeandlearn.co.uk/java/write_to_textfile.html

  1. package net.chinaunix.blog.hzm.text;

  2. import java.io.FileWriter;
  3. import java.io.PrintWriter;
  4. import java.io.IOException;

  5. public class WriteFile {

  6.     private String path;
  7.     private boolean appendToFile = false;
  8.     
  9.     public WriteFile(String filePath){
  10.         path = filePath;
  11.     }
  12.     
  13.     public WriteFile(String filePath, boolean appendvalue){
  14.         path = filePath;
  15.         appendToFile = appendvalue;
  16.         
  17.     }
  18.     
  19.     public void writeToFile(String textLine) throws IOException{
  20.         
  21.         FileWriter writer = new FileWriter(path,appendToFile);
  22.         PrintWriter printer = new PrintWriter(writer);
  23.         printer.printf("%s"+"%n",textLine);
  24.         printer.close();
  25.         /*The %s between double quotes means a string of characters of any length.
  26.           The %n means a newline. So we're telling the printf method to format a      string  of characters and add a newline at the end.
  27.          */
  28.         
  29.     }
  30.     
  31. }

  1. package net.chinaunix.blog.hzm.text;

  2. import java.io.IOException;

  3. public class FileData {

  4.     public static void main(String[] args) throws IOException{
  5.         
  6.         String filePath = "C:/text.txt";
  7.         
  8.     
  9.         try{
  10.             WriteFile writer = new WriteFile(filePath,true);
  11.           &n bsp; writer.writeToFile("This is another line..");
  12.         }catch(IOException e){
  13.             System.out.println(e.getMessage());
  14.         }
  15.     }
  16. }
 java.io.FileWriter

Whether or not a file is available or may be created depends upon the underlying platform. Some platforms, in particular, allow a file to be opened for writing by only one FileWriter (or other file-writing object) at a time. In such situations the constructors in this class will fail if the file involved is already open.

FileWriter is meant for writing streams of characters. For writing streams of raw bytes, consider using a FileOutputStream.

java.io.PrintWriter

Unlike the PrintStream class, if automatic flushing is enabled it will be done only when one of the println, printf, or format methods is invoked, rather than whenever a newline character happens to be output. These methods use the platform's own notion of line separator rather than the newline character.

Methods in this class never throw I/O exceptions, although some of its constructors may. The client may inquire as to whether any errors have occurred by invoking checkError().

您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國(guó)互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過(guò)ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP