Java.net.UnkownHostException: mailHost
Этот пример из учебника дает мне UnknownHostException
, Я помещаю свой адрес электронной почты в качестве аргументов консоли следующим образом: java MailClient ivan.ivanhoe@yahoo.com
Может кто-нибудь дать мне краткое объяснение, почему это невозможно, или посоветовать, как запустить / переписать приложение, чтобы оно могло отправлять почту. Спасибо хх
//MailClient.java
//Tries to send an email to my address : UnknownHostException. Trying to sort it now....
import java.net.*;
import java.io.*;
public class MailClient {
public static void main (String[] args) {
if (args.length == 0) {
System.err.println("Usage : java MailClient email@host.com");
return;
}
try {
URL u = new URL ("mailto:" + args[0]);
URLConnection uc = u.openConnection();
uc.setDoOutput(true);
uc.connect();
OutputStream out = uc.getOutputStream();
StreamCopier.copy(System.in, out);
out.close();
} catch (IOException e) {
System.err.print(e);
}
} //end main
}
import java.io.*;
public class StreamCopier {
public static void main (String[] args) {
try {
copy (null, null);
} catch (IOException e) {
System.err.println(e);
}
}
public static void copy (InputStream in, OutputStream out) throws IOException {
//do not allow other threads to read from the input or
//write to the output while copying is taking place.
synchronized (in) {
synchronized (out) {
byte [] buffer = new byte [256];
while (true) {
int bytesRead = in.read(buffer);
if (bytesRead == -1)
break;
out.write(buffer, 0, bytesRead);
}
}
}
} //end copy()
}