/** * 在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();}}}