JAVA代码下载TXT文件(本地和服务器上的代码都可以)
// 读取服务器文件内容(TXT文件测试可以) public static List<String> showTxt(String filePath) throws IOException{ FileInputStream fileInputStream = null; try{ fileInputStream = new FileInputStream(filePath); } catch (FileNotFoundException e){ e.printStackTrace(); } InputStreamReader fie = null; try{ fie = new InputStreamReader(fileInputStream,"GBK"); }catch(UnsupportedEncodingException e){ e.printStackTrace(); } BufferedReader by = new BufferedReader(fie); String line = ""; List<String> list = new ArrayList<String>(); while((line=by.readLine())!= null){ list.add(line); } fileInputStream.close(); fie.close(); by.close(); return list; }
一定要爱着点儿什么,恰似草木对光阴的钟情。