import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class Main
{
public static void main(String[] args) {
File file=new File("D:\\word.txt");
try
{
FileOutputStream out=new FileOutputStream(file);
byte buy[]="祝你生日快乐".getBytes();
out.write(buy);
out.close();
}catch(IOException a)
{
a.printStackTrace();
}
try
{
FileInputStream in =new FileInputStream(file);
byte by[]=new byte[1024];
int len=in.read(by);
System.out.println("信息是:"+new String(by,0,len));
in.close();
}catch (IOException c)
{
c.printStackTrace();
}
}
}
运行结果:信息是:祝你生日快乐
在D盘中word.txt中也有这句话:祝你生日快乐。