public static void main(String[] args) {
// TODO code application logic here
URL url;
try {
// get URL content
url = new URL("http://mp3.zing.vn/album/Chuyen-Tinh-Nha-Tho-Single-Van-Mai-Huong/ZWZAWZAZ.html");
URLConnection conn = url.openConnection();
// open the stream and put it into BufferedReader
BufferedReader br = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
String inputLine;
//save to this filename
String fileName = "G:\\test1.txt";
File file = new File(fileName);
if (!file.exists()) {
file.createNewFile();
}
//use FileWriter to write file
FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
while ((inputLine = br.readLine()) != null) {
bw.write(inputLine);
}
bw.close();
br.close();
System.out.println("Done");
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
当我在 netbean 上运行时,这段代码中的文本test1.txt
是可以的。当我在 Eclipse 上运行它时,结果:
�
�{�ב'�w��*_��f���b��/�%uu����DY[��̪JvUf�2�̬p1�;�w��w�;�}}yV��`0$�}�'���sN>��/���^A��<�8q"�ĉ��뛻�����?�k{�ַ�Z"��<(ld2��M���ƶ�Kg�d~&����=�.g2�����B�u3��� ���j�k��:i�7���-��d�w��-�j���H�n�,ݤ/��o�}ku�7>}��o�y�?����;���}�x`;ݾuCKi����������w�|�t�'�Z�=h�|V뻞<�VF4H��X��Ô���>ZIl��o9~�y:��!~�$|�����2z�ȳ�{�۩jB�0��GX
哪位大神帮忙解决一下,谢谢!!!