是写读url时报的错
源码和报错内容如下:
package exp3;
import java.io.*;
import java.net.*;
public class GetHtmlFile {
public static void main(String[] s) throws IOException, URISyntaxException {
URL url= new URL("http://www.swu.edu.cn");
InputStream is = url.openStream();
File file = new File(new URI("file:///E:\swu.txt"));
FileOutputStream fos = new FileOutputStream(file);
BufferedOutputStream bos = new BufferedOutputStream(fos);
int ch;
while((ch=is.read())!=-1)
{
bos.write(ch);
//bos.flush();
System.out.print((char)ch);
}
bos.close();
}
}
Exception in thread "main" java.net.URISyntaxException: Illegal character in path at index 10: file:///E: wu.txt
at java.base/java.net.URI$Parser.fail(URI.java:2963)
at java.base/java.net.URI$Parser.checkChars(URI.java:3134)
at java.base/java.net.URI$Parser.parseHierarchical(URI.java:3216)
at java.base/java.net.URI$Parser.parse(URI.java:3164)
at java.base/java.net.URI.<init>(URI.java:623)
at exp3/exp3.GetHtmlFile.main(GetHtmlFile.java:9)