提示:InputStream in = con.getInputStream(); //得到输入流
int n = 0;
byte bytes[] = new byte[1024]; // 用来存放读入的字节
StringBuffer contentBuffer = new StringBuffer(1024*1024); //bufferwhile (true) {
try {
n=in.read(bytes); //分批读入buffer中
if (n<0)
break;
String content = new String(bytes,0,n,"UTF-8"); //UTF-8编码
contentBuffer.append(content); //放入buffer中
}catch(Exception e){
}String data = contentBuffer.toString(); 当然你也可以根据情况自行修改。
int n = 0;
byte bytes[] = new byte[1024]; // 用来存放读入的字节
StringBuffer contentBuffer = new StringBuffer(1024*1024); //bufferwhile (true) {
try {
n=in.read(bytes); //分批读入buffer中
if (n<0)
break;
String content = new String(bytes,0,n,"UTF-8"); //UTF-8编码
contentBuffer.append(content); //放入buffer中
}catch(Exception e){
}String data = contentBuffer.toString(); 当然你也可以根据情况自行修改。
try{
RandomAccessFile raf = new RandomAccessFile("c:\\hello.txt","rw");
raf.writeBytes(data);
raf.close();
}catch(Exception e){
}