How to convert weird output of an array which printed to a file to its original value?

84 Views Asked by At

I have a char array that wrote in a file without any converting. the printed value to my file is [C@252ccf04 now I'm reading the file and this thing is being read as a string. now the retrieved data is [C@252ccf04 but this time it's a string. my problem is I want to assign it to another char array so I can read it using the Arrays.toString() method to reach the original value which is 123456 how can I accomplish that?

char[] pass = (data.substring(data.lastIndexOf(',') + 1).replaceAll(" ", "")).toCharArray();

System.out.println(Arrays.toString(pass));

// now the is: [[, C, @, 2, 5, 2, c, c, f, 0, 4]

and also I want to know what is this value what should I call it, is this a hashcode?

1

There are 1 best solutions below

0
On

The value is the hashcode(as hex) plus the name of the class. According to the default toString() implementation:

public String toString() {
    return getClass().getName() + "@" + Integer.toHexString(hashCode());
}

You can't convert it back to the original character array. The hash code identifies the object while it is alive in memory. Once the program ends and the object dies, you can't get it back from the hashcode.

You should have saved the actual data as a String, or encrypted it yourself.