package net.liuyx.test;import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.ByteBuffer;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;public class Test333 {
public static void main(String[] args){
String path = "http://192.168.128.1:8080/1.txt";
String result = getString(path);
System.out.println(result);
}
private static String getString(final String url){
try {
URL u = new URL(url);
HttpURLConnection conn = (HttpURLConnection) u.openConnection();
ReadableByteChannel channel = Channels.newChannel(conn.getInputStream());
ByteBuffer buffer = ByteBuffer.allocate(1024);
StringBuilder sb = new StringBuilder();
while(channel.read(buffer) != -1){
buffer.flip();
while(buffer.hasRemaining())
sb.append((char)buffer.get());
buffer.clear();
}
return sb.toString();
} catch (Exception e) {
throw new RuntimeException(e);

}
}高手勿喷