A file can be read as URL with the
java.net
package. You must provide absolute path after the URI scheme name file://
. package com.demo.io;
import java.io.*;
import java.net.*;
public class FileAsURL {
public static void main(String[] args) throws Exception {
URL url = new URL("file:///tmp/com/demo/io/test.txt");
URLConnection conn = url.openConnection();
BufferedReader r = new BufferedReader(
new InputStreamReader(
conn.getInputStream()
)
);
String l = r.readLine();
while (l != null) {
System.out.println(l);
l = r.readLine();
}
}
}
II have read your blog its very attractive and impressive. I like it your blog.
ReplyDeleteJava Training in Chennai Core Java Training in Chennai Core Java Training in Chennai
Java Online Training Java Online Training JavaEE Training in Chennai Java EE Training in Chennai