1. 程式人生 > >JAVA實現遠端檔案讀取

JAVA實現遠端檔案讀取

public class JavaReadRemoteFile {
	public static void main(String[] args) throws Exception {
		URL url = new URL("http://127.0.0.1/Test1/upload/1.txt");
		InputStream ism=url.openStream();
		byte[] bytes=new byte[1024];
		ism.read(bytes);
		String str=new String(bytes,"utf-8");
		System.err.println(str);
		while(ism.read(bytes)>-1){
			System.err.println(str);
		}
	}

}