0

I must use an existing method: method.invoke(myClassLoader, myFile.toURI().toURL()); where myFile is an instance of File and I need to create it from a byte[] without saving the file on the disk, is this possible?

This is what I tried but it creates a file on the disk and writes it:

    byte[] bytes = ...;
    File tempFile = File.createTempFile("prefix", "suffix");
    FileOutputStream fos = new FileOutputStream(tempFile);
    fos.write(bytes);
    method.invoke(myClassLoader, tempFile.toURI().toURL());

1 Answer 1

1

The parameter of the invoked method is URL. You can use Jimfs (An in-memory file system for Java 7+) to create a file emulation in memory and get its URL (path.toUri().toURL()).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.