public static String readFile(String xmlpath) { String fileText = ""; try { // 网络读取 URL url = new URL(xmlpath); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); DataInputStream input = new DataInputStream(conn.getInputStream()); InputStreamReader isr = new InputStreamReader(input, "utf-8"); // 本地读取 FileInputStream fis = new FileInputStream("D:\\aa.xml"); InputStreamReader isr = new InputStreamReader(fis, "utf-8"); BufferedReader br = new BufferedReader(isr); String line = null; while ((line = br.readLine()) != null) { fileText += line; fileText += "\r\n"; } } catch (Exception e) { e.printStackTrace(); } return fileText; }
O(∩_∩)O开心就好O(∩_∩)O