?? writeappendfile.java
字號:
package com.chapter4;
import java.io.*;
public class WriteAppendFile
{
//類成員變量
private String path;
private String content;
//初始化
public WriteAppendFile()
{
this.path = "";
this.content = "default content";
}
//設置文件路徑
public void setPath(String path)
{
this.path = path;
}
//得到文件路徑
public String getPath()
{
return this.path;
}
//設置要追加的字符串
public void setContent(String content)
{
this.content = content;
}
//得到要追加的字符串
public String getContent()
{
return this.content;
}
//追加字符串
public int writeContent()
{
int r = 0;
try
{
//創建文件path并寫入content字符串,注意和寫入篇的區別
FileWriter fWriter = new FileWriter(path,true);
PrintWriter out = new PrintWriter(fWriter);
out.print(this.content);
out.close();
//關閉文件
fWriter.close();
}
catch (IOException e)
{
r = -1;
}
return r;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -