我有一个文件oracle_publicsg.properties
这个文件中有serverName和port两个属性Properties settings = new Properties();
InputStream in = ClassLoaderUtil.getResourceAsStream(“oracle_publicsg.properties”, null); //这个方法是我写的可以返回流的。是正确的
settings.load(in);
settings.getProperty("port"); --打出来的结果是对的settings.setProperty("serverName",dbAddress);
settings.setProperty("port",port);但是
我要保存对这两个文件的修改,该怎么做?
这个文件中有serverName和port两个属性Properties settings = new Properties();
InputStream in = ClassLoaderUtil.getResourceAsStream(“oracle_publicsg.properties”, null); //这个方法是我写的可以返回流的。是正确的
settings.load(in);
settings.getProperty("port"); --打出来的结果是对的settings.setProperty("serverName",dbAddress);
settings.setProperty("port",port);但是
我要保存对这两个文件的修改,该怎么做?
解决方案 »
- JDBC驱动
- 英语单词词性还原问题
- socket监听问题
- Applet的paint(Graphics g)中的Graphics
- 這個用swing怎麼寫阿 很急
- 请教各位,如何使用object类的equals方法~~??
- 新手上路``````````撒200分算了~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- 使用SmartUpload 组件,如何将上传的文件更名?
- 怎样从javascript中获得一个applet里发生的事件,比如鼠标的点击等等
- Java 中定义数组失败,二维数组报错
- 怎么样才能在Log4j中改变日志运行时的行为!!!!!!!!!!!??????????????????????
- 当ResultSet 的对象到了最后一行后 如何返回到第一行?
InputStream in = ClassLoaderUtil.getResourceAsStream(“oracle_publicsg.properties”, null); settings.load(in);
settings.put("serverName",dbAddress);
settings.put("port",port);
楼主试试看,记得是这样的饿!
private String filepath="/uk/com/uid/example/in.properties";
public void readFile(String inString){
File in=new File(filepath);
String[] tmp=inString.split("\\|");
try {
FileInputStream filein=new FileInputStream(in);
Properties file=new Properties();
file.load(filein);
file.put("name",tmp[0]);
file.put("id",tmp[1]);
file.put("result",tmp[2]);
file.put("re",tmp[3]);
file.put("data",tmp[4]);
filein.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}public static void main(String[] args){
fileWrite fw=new fileWrite();
fw.readFile("a|b|c|d|e");
}
}试试这个看你就会明白了!呵呵!
Properties settings = new Properties();
try {
settings.load(new FileInputStream("oracle_publicsg.properties"));
System.out.println(settings.getProperty("serverName"));
settings.setProperty("serverName","3");
PrintWriter out=new PrintWriter(new FileOutputStream("oracle_publicsg.properties"));
out.print(settings);
out.flush();
out.close();
} catch (FileNotFoundException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
} catch (IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
FileInputStream fileIn = new FileInputStream(in);
Properties settings = new Properties();
settings.load(fileIn);
System.out.println("serverName from file" + settings.getProperty("serverName"));
settings.put("serverName",dbAddress);
settings.put("port",port);
settings.put("username",userName);
settings.put("password",userPwd);
fileIn.close();
办不到!我很郁闷
document 是这样的