/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package kommentarborttagare; import java.io.*; import java.util.logging.Level; import java.util.logging.Logger; /** * * @author Diana */ public class Kommentarborttagare { /** * @param args the command line arguments */ public static void main(String[] args) { Kommentarborttagare obj = new Kommentarborttagare(); obj.taBortKommentarer("fil.txt"); } public void taBortKommentarer(String filnamn){ try { File f = new File(filnamn); FileReader fr = new FileReader(f); BufferedReader br = new BufferedReader(fr); FileWriter fw = new FileWriter("uncommented_"+filnamn); BufferedWriter bw = new BufferedWriter(fw); String rad = br.readLine(); while(rad!=null){ rad = rad.replaceFirst("//.*",""); bw.write(rad); bw.newLine(); rad = br.readLine(); } bw.close(); br.close(); }catch (FileNotFoundException ex) { System.out.printf("Filen "+filnamn +"hittades ej!"); } catch (IOException ex) { System.out.printf("Skrivfel"); } } }