FileWriter fw = new FileWriter(File.....);
fw.write("......");
.....
fw.flush();
fw.close();应该ok
fw.write("......");
.....
fw.flush();
fw.close();应该ok
解决方案 »
- 实现了鼠标的监听器类为什么没有反应呢?
- mysql的一个小问题
- 求一个关于编码转换的问题,在线等
- http 连接问题,帮个忙~~~
- Collection 和 Collections的区别。
- 不能初始化内部类,请大家看看是怎么回事?
- ?????????
- 困扰了小弟很久的播放器不能实例化的问题(自己写的一个播放器,还在建设中),有兴趣的可意见来看下,代码很长,小弟菜鸟一个,大家请多
- 如何用JDBC-ODBC桥连接sql server数据库?(在线)
- java Runtime.getRuntime().exec(cmd)调用问题
- tomcat4.1.1的管理员用户名与密码是什么呀
- 网络编程高手请进:关于Telnet程序的小问题!
FileOutputStream fos = new FileOutputStream("test.txt",true);
FileOutputStream public FileOutputStream(String name,
boolean append)
throws FileNotFoundException
Creates an output file stream to write to the file with the specified name. If the second argument is true, then bytes will be written to the end of the file rather than the beginning. A new FileDescriptor object is created to represent this file connection. First, if there is a security manager, its checkWrite method is called with name as its argument.
If the file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason then a FileNotFoundException is thrown.
Parameters:
name - the system-dependent file name
append - if true, then bytes will be written to the end of the file rather than the beginning
Name =
State = 我现在要向 Name 的后面加一个值! 怎么半啊?
FileOutputStream fos = new FileOutputStream("test.txt",true);
****
append 标志位设为 true 为加入到文件后
FileOutputStream fos = new FileOutputStream("test.txt",true);
****
append 标志位设为 true 为加入到文件后
要不然定位到Name也是比较麻烦的。
import java.util.*;
import java.io.*;public class Test {
public static void main(String[] args) {
try {
Properties p = new Properties();
FileInputStream in = new FileInputStream("test.txt");
p.load(in);
in.close();
System.out.println(p.getProperty("Name"));
} catch(Exception e) {
System.out.println(e.getMessage());
}
}
}
import java.io.*;public class Test {
public static void main(String[] args) {
try {
Properties p = new Properties();
FileInputStream in = new FileInputStream("test.txt");
p.load(in);in.close();System.out.println(p.getProperty("Name"));
*********************************************// Set Name's valuep.setProperty("Name", "456");
System.out.println(p.getProperty("Name"));*********************************************} catch(Exception e) {
System.out.println(e.getMessage());
}
}
}
作,具体的类叫RadomAccessFile。很简单,你看看API把
import java.io.*;public class Test {
public static void main(String[] args) {try {
Properties p = new Properties();
FileInputStream in = new FileInputStream("test.txt");
p.load(in);
FileOutputStream out = new FileOutputStream("test.txt");
Enumeration enum = p.propertyNames();
while(enum.hasMoreElements()) {
String s = enum.nextElement().toString();
if(s.equals("Name")) {
//#####################################
// Name is the Key you want to change
// 789 is the new value you want to set
p.setProperty("Name", "789");
//#####################################
}
else {
//#####################################
// Remain orgin value
p.setProperty(s, p.getProperty(s));
//#####################################
}}in.close();
p.store(out, "Test");
} catch(Exception e) {
System.out.println(e.getMessage());
}
}
}
PrintWriter out=new PrintWriter(new FileWriter(f.getName(),true),true);记得给分
PrintWriter out=
new PrintWriter(new FileWriter(f.getName),true),true);out.write("AAAA");
out.flush();
out.close();
PrintWriter out=
new PrintWriter(new FileWriter(f.getName(),true),true);
out.println("aaaa");
out.flush();
out.close();