我在一個項目中需要使用C:\WINDOWS\system
import java
import java
import java
public class FileWriterTest {
public static void main(String[] args) {
FileOutputStream stream ;
OutputStreamWriter writer;
try {
//主要是使用了FileOutputStream的構造函數FileOutputStream(File file
//這裡參數append為true表示可以添加
stream = new FileOutputStream(
writer = new OutputStreamWriter(stream);
writer
writer
stream
} catch (IOException e) {
e
}
}
}
以上代碼在eclipse上調試成功!
為了增加代碼的重用性
public void appendToFile(String str
{
// Open up an outputstreamwriter to the file
FileOutputStream stream;//provides file access
OutputStreamWriter writer;//writes to the file
try
{
stream = new FileOutputStream(filename
writer = new OutputStreamWriter(stream);
writer
writer
stream
}
catch(Exception e)
{
throw e;
}
}//appendToFile
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26427.html