Replace Null Characters (ASCII 0) in file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • teenIce
    New Member
    • Aug 2007
    • 36

    Replace Null Characters (ASCII 0) in file

    Hi,

    I have a java code that open and read a file. My problem is the file had null char, that had been saved by flash. This null char represent new line in text.
    My question is, how can I replace the null char with the new line tag.

    Thanks in advance.
  • Nepomuk
    Recognized Expert Specialist
    • Aug 2007
    • 3111

    #2
    Originally posted by teenIce
    Hi,

    I have a java code that open and read a file. My problem is the file had null char, that had been saved by flash. This null char represent new line in text.
    My question is, how can I replace the null char with the new line tag.

    Thanks in advance.
    This does the job:
    [CODE=java]
    public static void main(String[] args)
    {
    char ascii0 = 0; // Characters can be defined by their ASCII value
    char[] hello = ("Here comes a " + ascii0 + "new line.").toCharA rray(); // Create a String, which contains an ASCII 0 and convert it to a char array
    System.out.prin tln(new String(hello)); // Print it (just for checking)

    for(int i=0;i<hello.len gth;i++)
    {
    if(hello[i] == 0) hello[i] = '\n'; // If it finds a ASCII 0, it should replace it by a new line character
    }
    System.out.prin tln("\n" + new String(hello)); // Print the result (just for checking)
    }
    [/CODE]

    Comment

    Working...