0

I Have used a byte Array like this:

byte[] fileContents =  Files.readAllBytes(path);
    for(int i = 0 ,j = 1; i <fileContents.length ; i++)
        FileContents += Integer.toBinaryString(fileContents[i]);

        System.out.println(FileContents);

but when I run this on a File containing :

Ananay

it shows this:

java.lang.NullPointerException
at java.lang.String.replace(String.java:2239)
at UEX.<init>(UEX.java:21)
at test.testEncryption(test.java:38)
at __SHELL54.run(__SHELL54.java:5)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at bluej.runtime.ExecServer$3.run(ExecServer.java:743)

Thanks in advance.

(I prefer to use a String in this case even though it is not recommended)

Ananay Gupta
  • 355
  • 3
  • 14
  • Is your `FileContents` variable initialized? because if it is not then it won't work – Lino Oct 22 '17 at 14:04
  • No. Read the stack trace. The exception is thrown from the String.replace() method, which is itself called from the constructor in UEX, at line 21. So it has nothing to do with the code you posted, which never calls replace(). – JB Nizet Oct 22 '17 at 14:06
  • @Lino Thanks a lot! That was Exactly what it is. – Ananay Gupta Oct 22 '17 at 14:18
  • @JBNizet Thanks to you too. I had removed the replace function but put its Stack Trace up – Ananay Gupta Oct 22 '17 at 14:19

0 Answers0