| | |
| | | * @throws IOException 如果发生I/O错误 |
| | | */ |
| | | public static InputStream downloadAsStream(String urlString) throws IOException { |
| | | // 找到最后一个斜杠的位置 |
| | | int lastSlashIndex = urlString.lastIndexOf("/"); |
| | | // 从斜杠后提取文件名 |
| | | String baseUrl = urlString.substring(0, lastSlashIndex); |
| | | String fileName = urlString.substring(lastSlashIndex + 1); |
| | | String encode = URLEncoder.encode(fileName, "UTF-8"); |
| | | urlString = baseUrl + "/" + encode; |
| | | URL url = new URL(urlString); |
| | | HttpURLConnection connection = (HttpURLConnection) url.openConnection(); |
| | | connection.setRequestMethod("GET"); |