我要在Hello.txt中输入内容应该怎么做呢?public class Ex6_2 {
public Ex6_2()
{
}
public static void main(String arg[])throws IOException{
File f = new File("D:" + File.separator + "Hello.txt");
f.createNewFile();
FileInputStream in=new FileInputStream("Hello.txt");
}
public Ex6_2()
{
}
public static void main(String arg[])throws IOException{
File f = new File("D:" + File.separator + "Hello.txt");
f.createNewFile();
FileInputStream in=new FileInputStream("Hello.txt");
}
import java.io.*;
public class Ex6_2 {
public static void main(String arg[])throws IOException{
File f = new File("D:" + File.separator + "Hello.txt");
f.createNewFile();
s1 += "要添加的内容";
BufferedWriter output = new BufferedWriter(new FileWriter(f));
output.write(s1);
output.close();
}
要的是这个效果吗?
在D:/下,建立Hello.txt文件,然后把s1的内容写入文件中
import java.io.*;
public class test
{
public static void main(String args[]) throws IOException
{
String s;
File file = new File("D:/123.txt");
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(new FileWriter(file));
System.out.print("输入的内容:");
while((s = in.readLine())!=null)
{
out.write(s);
}
in.close();
out.close();
}
}
上面的程序,在D盘下建个文件,把输入的内容存入该文件,不过在输入完想要写入的内容后,先按回车,再ctrl-z,才能存入文件~~
fw.write("content");
fw.close();
File file = new File("D:\Hello.txt");
FileWriter writer=new FileWriter(file);
writer.write(str);
writer.close() ;
FileWriter filewriter=new FileWriter(file);
String s=new String();
filewrite.write(s);
filewrite.close();