Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Logger wirtes zero values to file

  1. #1
    Junior Member
    Join Date
    Jun 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Logger wirtes zero values to file

    Hi everyone,

    My logger writes a sequence of strings in a file by the java.io.PrintStream.println() method.
    In some case a line in log is formed by a sequence of zero values (that is 0x0, not zero in ASCII code, 0x30).

    I would like to know two things:

    1) In which cases it may happen?
    2) I would like to replicate the error: how can I do so as to write zero values in file?


    Thanks in advance for yours answers.

    Best regards,

    Matteo


  2. #2
    Junior Member
    Join Date
    Jun 2013
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Logger wirtes zero values to file

    We will be able to help you more if you post some of the related code. 0x0 is the value for null. You can print null to a file by doing this println(null);
    I hope this helps.
    Last edited by theonlydvr; June 29th, 2013 at 01:47 PM. Reason: Better information

  3. #3
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    987
    Thanks
    6
    Thanked 206 Times in 182 Posts

    Default Re: Logger wirtes zero values to file

    0x0 is the value for null. You can print null to a file by doing this println(null);
    I'm not sure that's right. As far as I know a PrintStream instance passed a variable or expression that evaluates to null will print the four letters "null" (which has the merit of being readable) and not the single letter 0x0.

    Also "println(null);" is ambiguous, you would have to cast the null to something. (Eg a String.)

    ---

    @OP: You are getting lines of the zero character because somewhere in the code you haven't posted you are telling the PrintStream instance to print them. You can do this, eg, by using the character literal '\0', or by using the same escape sequence inside a string literal:

    String str = "\0\0";
    System.out.println("The next line contains a couple of zero characters:");
    System.out.println(str);        
    System.out.println(str.length());

Similar Threads

  1. Read and write to a text file and calculate values
    By s.sariyan in forum What's Wrong With My Code?
    Replies: 19
    Last Post: November 28th, 2012, 10:19 AM
  2. counting the values in input file and and writing the output to a file
    By srujirao in forum What's Wrong With My Code?
    Replies: 3
    Last Post: July 8th, 2012, 02:48 PM
  3. Replies: 3
    Last Post: December 2nd, 2011, 11:53 AM
  4. [SOLVED] compare form values with database values
    By VaniRathna in forum Java Servlet
    Replies: 2
    Last Post: October 24th, 2011, 02:48 AM
  5. Read A File and Store Values into a 2-Dimensional Integer Array?
    By Kimimaru in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 9th, 2011, 09:13 PM