import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class h {
public static void main(String aegs[]){
FileWriter fw;
String str1 = "\"1.0\"";
String str2 = "\"UTF-8\"";
String str3 = "
";//使用双引号的方法
try {
fw = new FileWriter("E:/测试.xml");
//fw = new FileWriter("E:/io_1.txt",true);这个是追加内容的方法
fw.write(str3+"\r\n");
fw.write("
哇哈哈*!@#%……&*(()+——《》?
\r\n");//反斜杠不可以用
fw.write("-------{}:|:>?|/-*~]['");
fw.flush();
fw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
FileReader fr=new FileReader("E:/测试.xml");
int i;
try {
while((i=fr.read())!=-1){
System.out.print((char)i);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
IO流输出输入
最新推荐文章于 2021-07-17 14:27:56 发布