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;
	}

  

posted on 2021-04-09 11:05  海哥哥99  阅读(819)  评论(0编辑  收藏  举报

导航