Java tutorial
//package com.java2s; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; import java.io.StringWriter; import java.net.URL; public class Main { public static String getDtdAsString(String uri) throws IOException { Reader in = null; if ((uri.startsWith("http")) || (uri.startsWith("ftp")) || (uri.startsWith("file:"))) in = new InputStreamReader(new URL(uri).openStream()); else { in = new FileReader(uri); } StringWriter out = new StringWriter(); char[] buffer = new char[4096]; for (int count = in.read(buffer); count != -1; count = in.read(buffer)) { out.write(buffer, 0, count); } return out.getBuffer().toString(); } }