創建新的class -CreateFile
import
java.io.*;
import
java.lang.*;
import
java.util.*;
public
class
createfile {
private
Formatter x;
public
void
openFile(){
try{
x=
new
Formatter("chinese.txt");
}
catch(Exception
e){
System.out.println("you
have an error");
}
}
public
void
addRecords(){
x.format("%s%s%s",
"20
",
"bucky
","roberts");
→你把什麼放在文件中
}
public
void
closeFile(){
x.close();
→必須close();
}
}
在apples.java:
class
apples{
public
static
void
main(String[] args){
createfile
g = new
createfile();
g.openFile();
g.addRecords();
g.closeFile();
}
}
然後,當你創建。你可以點擊chinese.txt文件:
20
bucky
roberts
沒有留言:
張貼留言