0

Is it possible? Basically I have a local binary file represented by:

file:///path/to/myfile.dat

I want to read this file using ByteBuffers, in other words, I believe I need a FileChannel from the given URL to do that.

Any hope?

2
  • @JohnD It is a URL. It has a scheme and a scheme-dependent part. Commented Oct 30, 2017 at 0:10
  • 1
    @JohnD I tried with my browser and I can open a local file. The correct URL has 3 '/' instead of 2 (my bad) => file:///path/to/mylocalfile.dat (Obs: I fixed my original URL that had incorrectly two '/' instead of 3) Commented Oct 30, 2017 at 0:11

1 Answer 1

1

Yes, just get the path out of the URL and open it with FileChannel.open().

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

1 Comment

Calling URL.getPath() or URL.getfile() will not return a valid filename. It will return the path portion of the URL, with all percent escapes. A URL should be converted to a Path with Paths.get(url.toURI()).

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.