BufferedReader BufferedWriter HttpURLConnection

			BufferedReader和BufferedWriter: 字符流, BufferedReader有readline()方法
			从网络中读取数据
			URL url = new URL(urlStr);
			HttpURLConnection con = (HttpURLConnection)url.openConnection();
			BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));
			
			BufferedWriter bw = new BufferedWriter(new FileWriter(file));
			BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
			bw.write("something");
			bw.newLine();
			bw.close();
			
			BufferedReader br = new BufferedReader(new FileReader(file));
			BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file)));
			String line = br.readLine();
			
			InputStream与OutputStream: 字节流		 //常用于处理图片、声音等二进制文件,汉字之类的无法处理,如“a你好”
			BufferedInputStream与BufferedOutputStream 处理字节流
			BufferedInputStream bis = new BufferedInputStream(con.getInputStream());
			
			BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
			BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file1));
			
			while (bis.available() > 0) {
				System.out.println((char)bis.read()); //bis.read()返回ASCII码值:int
			}
			
			byte[] buffer = new byte[1024];
			int num = -1;
			while((num = bis.read(buffer)) != -1){
				System.out.println("hello");
				bos.flush();
				bos.write(buffer, 0, num);
			}
			bos.close();
			bis.close();

你可能感兴趣的:(Java)