try {
URL url = new URL("ftp://username:password@url.net/FileToWrite.txt");
URLConnection urlc = url.openConnection();
OutputStream os = urlc.getOutputStream();
OutputStream buffer = new BufferedOutputStream(os);
ObjectOutput output = new ObjectOutputStream(buffer);
output.writeChars("hello");
buffer.close();
os.close();
output.close();
} catch (IOException e) {
System.out.println(e);
}
这段代码给了我一个套接字异常,请帮助我输掉
答案 0 :(得分:0)
这适用于Java 8:
try {
URL url = new URL("http://cnn.com"); /* Tested on a real URL */
URLConnection urlc = url.openConnection();
urlc.setDoOutput(true); /* Added this ... */
OutputStream os = urlc.getOutputStream();
OutputStream buffer = new BufferedOutputStream(os);
ObjectOutput output = new ObjectOutputStream(buffer);
output.writeChars("hello");
buffer.close();
os.close();
output.close();
System.out.println("Done");
} catch (IOException e) {
e.printStackTrace();
}
让您的生活更轻松