淇敼鏂囦欢鍐呭

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 鏂囦欢鐨勬渶杩戣闂?+ 灞炴€т慨鏀?+ 鍐呭淇敼鏃堕棿

鎵归噺淇敼鏂囦欢鍚嶅瓧

oracle 淇敼鏁版嵁鏂囦欢璺緞

閰嶇疆php.ini 淇敼php鏂囦欢涓婁紶澶у皬

MATLAB璇诲彇鏂囦欢鈥斺€斾粠闈炲父瑙勬枃鏈枃浠朵腑璇诲彇鏁版嵁

鏌ョ湅鏂囦欢鍜屾枃浠跺す澶у皬