Reading a file from the file system using the URL class ...

I have a file in my own my file system say : c:/temp/pdf/a.pdf

I want to read it ... can I do something like this URlL u = new URL("c:/temp/pdf/a.pdf");

But this gives me Malformed exception. Is there a way I can use the URL class or else what are the alternatives ...

Why I am stressing on URL is since our frameworks accepts URL then I am saved of lot of code ...

Thanx in advance,

RK

rahulkothariAsked:
Who is Participating?
 
aozarovConnect With a Mentor Commented:
You can by doing: URlL u = new URL("file:/c:/temp/pdf/a.pdf");
But you can also use FileInputStream("c:/temp/pdf/a.pdf");
0
 
CEHJCommented:
URlL u = new URL("file:/c:/temp/pdf/a.pdf");
0
 
aozarovCommented:
bsh % URL url = new URL("file:/g:/java-temp/T.java");
bsh % url.openStream();
<java.io.BufferedInputStream@1320a41>
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
CEHJCommented:
Safer actually to do

URL url = new File"xxxxxxxxxxxx").toURL();


0
 
CEHJCommented:
Or rather

URL url = new File("xxxxxxxxxxxx").toURL();
0
 
aozarovCommented:
:-)
0
All Courses

From novice to tech pro — start learning today.