杨幂大胸视频:请问用java创建一个TXT文件,文件里写“你好”,代码怎么写

来源:百度文库 编辑:高考问答 时间:2024/04/29 10:18:38

 
 
 
这样写就可以了:

import java.io.*;

class C {
    public static void main( String[ ] args ) throws Exception {
        PrintWriter pw = new PrintWriter( new FileWriter( "问好.txt" ) );
        pw.print( "你好" );
        pw.close( );
    }
}

 
 
 

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;

public class Io{
public static void main(String [] s){
File filename = new File("F:\\suncity.txt");

String filein="你好!";
RandomAccessFile mm = null;
try {
mm = new RandomAccessFile(filename,"rw");

mm.writeBytes(filein);

} catch (IOException e1) {
// TODO 自动生成 catch 块
e1.printStackTrace();
} finally{
if(mm!=null){
try {
mm.close();
} catch (IOException e2) {
// TODO 自动生成 catch 块
e2.printStackTrace();
}
}
}

}

}