javaio流从指定文件夹中读取信息显示到文本框中该怎么做啊,求完整代码,谢大神了
使用工具类Properties
工具类有Load()方法 用于加载文件
首先将文件写成流(输入)File file=new File(confPath); in = new FileInputStream(file);
加载流load(in)如果需要操作则完成具体操作
输出流并保存文件out2 = new OutputStreamWriter(new FileOutputStream(confPath),"GBK"); cp.store(out2);完成
具体实例代码public String updateConfParam(ConfParam cpl) throws IOException { String error = null; Properties cp=new Properties(); InputStream in= null; OutputStreamWriter out1=null; OutputStreamWriter out2=null; JSONObject jObj = new JSONObject(); try { String confPath=validateSystem(cpl.getConfAddress()+"/"+cpl.getConfName()); File file=new File(confPath); in = new FileInputStream(file); cp.load(in); out1=new OutputStreamWriter(new FileOutputStream(confPath+".bak"),"GBK"); cp.store(out1); cpl.setParaOldValue(cp.getProperty(cpl.getParaKey())); cp.setProperty(cpl.getParaKey(), cpl.getParaValue()); out2 = new OutputStreamWriter(new FileOutputStream(confPath),"GBK"); cp.store(out2); jObj.put("paraOldValue", cpl.getParaOldValue()); jObj.put("paraValue", cpl.getParaValue()); } catch (FileNotFoundException e) { error=e.getMessage(); } catch (IOException e1) { error = e1.getMessage(); } finally{ if(in !=null){ in.close(); } if(out1 !=null){ out1.close(); } if(out2 !=null){ out2.close(); } if(error != null){ jObj.put("error", error); } } return jObj.toString(); }