import java.io.*;
import java.util.*;class shiyan
{
public static void main(String[] agrs) throws IOException
{
PrintWriter out=new PrintWriter(new FileWriter("d.txt"));
out.println("hsiydfskdkfs kfsdkfksdfksdfsdjdfsdkj");
}
}
为什么这段代码能通过编译和运行,而且在当前目录下能生成d.txt文件,但println中的字符串却写不进去??
import java.util.*;class shiyan
{
public static void main(String[] agrs) throws IOException
{
PrintWriter out=new PrintWriter(new FileWriter("d.txt"));
out.println("hsiydfskdkfs kfsdkfksdfksdfsdjdfsdkj");
}
}
为什么这段代码能通过编译和运行,而且在当前目录下能生成d.txt文件,但println中的字符串却写不进去??
import java.util.*;class shiyan
{
public static void main(String[] agrs) throws IOException
{
PrintWriter out=new PrintWriter(new FileWriter("d.txt"));
out.println("hsiydfskdkfs kfsdkfksdfksdfsdjdfsdkj");
out.flush();
}
}
就可以了哈
import java.util.*;class shiyan
{
public static void main(String[] agrs) throws IOException
{
PrintWriter out=new PrintWriter(new FileWriter("d.txt"));
out.write("hsiydfskdkfs kfsdkfksdfksdfsdjdfsdkj");
out.close();
}
}
成功了!!!