Results 1 to 3 of 3
  1. #1
    manish250 is offline Member
    Join Date
    Dec 2010
    Posts
    3
    Rep Power
    0

    Default issue in file io

    hello all

    i am doing a copy operation from a file to another file.in source file i have 13 digit no but in destination file there is only 12 digit copied.code is as follows.
    Java Code:
    public void createOriganalFile() {
        try {
         
        File ObjInputFile1 = new File(strFilepath + "_dummy.txt");
        File ObjOutputFile1 = new File(strFilepath);
        String strLine1 = "";
        BufferedReader ObjBufferReaderIn1 = new BufferedReader(new FileReader(ObjInputFile1));
        BufferedWriter ObjBufferReaderOut1 = new BufferedWriter(new FileWriter(ObjOutputFile1));
        do {
        if ((strLine1 = ObjBufferReaderIn1.readLine()) == null) {
        System.out.println("strLine1 is null");
        break;
        }
        System.out.println("strLine--------- " + strLine1 +" strFilepath " + strFilepath);
        ObjBufferReaderOut1.write(strLine1,0,13);
        ObjBufferReaderOut1.newLine();
        ObjBufferReaderOut1.flush();
        System.out.println("Here After: "+strLine1);//13 digit no
         
         
         
        } while (true);
         
        //ObjInputFile.delete();
        ObjBufferReaderIn1.close();
        ObjBufferReaderOut1.close();
        ObjBufferReaderIn2.close();
        } catch (Exception ex) {
        ex.printStackTrace();
        }
        }

  2. #2
    dlorde is offline Senior Member
    Join Date
    Jun 2008
    Posts
    339
    Rep Power
    7

    Default

    Works OK for me.

    Incidentally, why have a 'do' loop forever with a break check, instead of just a simple while loop ? e.g.
    Java Code:
    while ((strLine1 = objBufferReaderIn1.readLine()) != null) {
       ...
       ...
    }
    p.s. Java Naming Conventions are that class names start with an uppercase letter, method and variable names start with a lowercase letter.

  3. #3
    manish250 is offline Member
    Join Date
    Dec 2010
    Posts
    3
    Rep Power
    0

    Default

    yes you are right.I have made the changes according to you.it is running same in my window system.but why it is not running in RHEL 5

Similar Threads

  1. BufferedReader File into Array Issue
    By LifeElixer in forum New To Java
    Replies: 4
    Last Post: 04-13-2011, 01:33 AM
  2. Replies: 0
    Last Post: 01-18-2011, 03:00 AM
  3. Lo4j issue - logs are written in a wrong file
    By Dhamo in forum Advanced Java
    Replies: 0
    Last Post: 05-09-2010, 10:11 PM
  4. Exporting WAR File Issue
    By bsimic in forum Eclipse
    Replies: 0
    Last Post: 12-29-2009, 04:23 PM
  5. file trasferring issue
    By MarkWilson in forum CLDC and MIDP
    Replies: 1
    Last Post: 03-10-2009, 02:54 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •