淇敼鏂囦欢鍐呭
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了淇敼鏂囦欢鍐呭相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/get' title='get'>get
string equals trace upd stack append adl catch/*** * * @param path 鏂囦欢鍦板潃 鏂囦欢榛樿瀛樿串 * @param key 閫氳繃key鎵惧埌瑕佷慨鏀圭殑瀵瑰簲琛岀殑value * @param newValue 鏇挎崲鍊? */ public static void replaceTxt(String path,String key,String newValue) { String temp = ""; try { //璇诲彇鏂囦欢 File file = new File(path); FileInputStream fis = new FileInputStream(file); InputStreamReader isr = new InputStreamReader(fis); BufferedReader br = new BufferedReader(isr); //鏂囦欢鍐呭涓存椂淇濆瓨 StringBuffer buf = new StringBuffer(); // 淇濆瓨璇ヨ鍓嶉潰鐨勫唴瀹?/span> while ( (temp = br.readLine()) != null) { //鍒ゆ柇鏄惁鏄淇敼鐨勫搴旇 boolean isUpdata=temp.equals(key); if(isUpdata){ //淇敼瀵瑰簲琛岀殑鍊?/span> buf = buf.append(newValue); }else{//淇濆瓨涓嶇敤淇敼鐨勫€?/span> buf = buf.append(temp); } //娣诲姞鎹㈣ buf = buf.append(System.getProperty("line.separator")); } //鍏抽棴璇绘祦 br.close(); //骞跺皢鏂囦欢閲嶆柊鍐欏叆 FileOutputStream fos = new FileOutputStream(file); PrintWriter pw = new PrintWriter(fos); pw.write(buf.toString().toCharArray()); pw.flush(); pw.close(); } catch (IOException e) { e.printStackTrace(); } }
以上是关于淇敼鏂囦欢鍐呭的主要内容,如果未能解决你的问题,请参考以下文章
Python3鍩虹 getatime getctime getmtime 鏂囦欢鐨勬渶杩戣闂?+ 灞炴€т慨鏀?+ 鍐呭淇敼鏃堕棿