0

I am trying to generate a texlipse file with the help of BufferedReader to read another texlipse file and write into the texlipse file to be generated using BufferedWriter and in this process I am printing the content read by the BufferedReader to console also. In doing so I am not able to read some characters like \u, \b, \v, and I cannot neglect those as my texlipse need those while writing latex code.

package jchart2Dt;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;

public class practice3 {

    public static BufferedWriter bw;

    static String sensitivity = "0.556";
    static String offset = "0.125";

    public static void main(String[]args) throws NullPointerException{

        String pathname = "D:\\Messdaten\\CalibrationCertificate\\document.tex";
        File file = new File(pathname);

        InitialiseWriter();
        try{
            FileReader f = new FileReader(file);
            BufferedReader br= new BufferedReader(f);

            while(br.readLine()!= null){

                String content = br.readLine();
                System.out.println(content);
                content = check(content);
                WriteCertificate(content);
            }
            bw.close();
            f.close();
        }catch(Exception e){
            e.printStackTrace();
        }
    }

    public static void InitialiseWriter()  {
        // TODO Auto-generated method stub
        File file = new File ("D:\\Messdaten\\CalibrationCertificate\\certificate.tex");
        try {
            if(!file.exists()){
                file.createNewFile();
            }
            FileWriter fw = new FileWriter(file.getAbsoluteFile());
            bw=new BufferedWriter(fw);
        } catch (Exception e) {}
    }

    public static String check(String line_content) {

        String output = line_content.replace("<<sensitivity>>", sensitivity);
        output = output.replace("<<offset>>", offset);
        return output;

    }
    public static void WriteCertificate(String content)  {
        try{
            bw.write(content +"\n");
        }catch(Exception e){}

    }

}
Codebender
  • 14,221
  • 7
  • 48
  • 85
jenny
  • 500
  • 7
  • 22
  • 2
    You are skipping every other line by calling `br.readLine()` twice. – Codebender Jul 18 '16 at 13:52
  • This has an answer already here : http://stackoverflow.com/questions/4597749/read-write-txt-file-with-special-characters – SomeDude Jul 18 '16 at 13:54
  • Ohhh yaaa... I observed it now, so it is the problem... what to do? – jenny Jul 18 '16 at 13:54
  • @Codebender : I have commented every other piece of code and just observed reading of lines procedure in my code , and saw the same output with every other line skipped , Iam not able to find where did i call it twice. – jenny Jul 18 '16 at 14:04
  • @Codebender yuppp got it.. my piece of code goes like this. Thankyou. while((content = br.readLine())!= null){ System.out.println(content); } – jenny Jul 18 '16 at 14:21

0 Answers0