当前位置: 技术问答>java相关
URLConnection.getOutputStream()相关问题
来源: 互联网 发布时间:2015-06-02
本文导语: try{ URL url=new URL("http://localhost:8080/forum/file/test.txt"); URLConnection uc=url.openConnection(); PrintWriter pw=new PrintWriter(uc.getOutputStream()); pw.write("hello!!!!"); ...
try{
URL url=new URL("http://localhost:8080/forum/file/test.txt");
URLConnection uc=url.openConnection();
PrintWriter pw=new PrintWriter(uc.getOutputStream());
pw.write("hello!!!!");
pw.flush();
}catch(Exception e){e.printStackTrace();}
发布时不能写入;但我试个URL.openURLConnection.getInputStream();又可以,为什么?谢谢!!
URL url=new URL("http://localhost:8080/forum/file/test.txt");
URLConnection uc=url.openConnection();
PrintWriter pw=new PrintWriter(uc.getOutputStream());
pw.write("hello!!!!");
pw.flush();
}catch(Exception e){e.printStackTrace();}
发布时不能写入;但我试个URL.openURLConnection.getInputStream();又可以,为什么?谢谢!!
|
URL url=new URL("http://localhost:8080/forum/file/test.txt");
URLConnection uc=url.openConnection();
//设一下
uc.setDoOutput( true );
uc.setDoInput( true );
uc.setUseCaches( false );
PrintWriter pw=new PrintWriter(uc.getOutputStream()); //最好改为
BufferedOutputStream pw = new BufferedOutputStream(uc.getOutputStream());
pw.write("hello!!!!");
pw.flush();
URLConnection uc=url.openConnection();
//设一下
uc.setDoOutput( true );
uc.setDoInput( true );
uc.setUseCaches( false );
PrintWriter pw=new PrintWriter(uc.getOutputStream()); //最好改为
BufferedOutputStream pw = new BufferedOutputStream(uc.getOutputStream());
pw.write("hello!!!!");
pw.flush();