複製代碼去除行號

來源:互聯網
上載者:User
/** * 在CSDN、javaeye 等各大IT網站複製執行個體代碼時候,在每行代碼前總會有行數序列 * 手動一個一個刪除序列太麻煩,於是寫了個方法自動刪除 * 例如複製過來的代碼: *      001 第一行代碼 *      002 第二行代碼 *      003 第三行代碼 *  * @param path01 要替換的代碼路徑 * @param path02 替換後代碼的路徑 * @param index 首碼數字位元 */public static void getJavaCode(String path01, String path02,int index) {FileInputStream fis = null;InputStreamReader isr = null;FileOutputStream fos = null;OutputStreamWriter osw = null;BufferedReader br = null;BufferedWriter bw = null;String line = null;try {fis = new FileInputStream(path01);isr = new InputStreamReader(fis);br = new BufferedReader(isr);fos = new FileOutputStream(path02, true);osw = new OutputStreamWriter(fos);bw = new BufferedWriter(osw);while ((line = br.readLine()) != null) {if (line.length() > index) {String newline = line.substring(index, line.length());bw.write(newline + "\r\n");System.out.println(newline);}}} catch (FileNotFoundException e) {e.printStackTrace();} catch (Exception e) {e.printStackTrace();} finally {try {if (bw != null) {bw.close();}if (osw != null) {osw.close();}if (fos != null) {fos.close();}if (br != null) {br.close();}if (isr != null) {isr.close();}if (fis != null) {fis.close();}} catch (IOException e) {e.printStackTrace();}}}

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.