我想从我自己的服务器上下载一个大的 .jar 文件。( https://luis.team ) 在那里我做了一个线程来下载它,因为它非常巨大。这是我的下载代码:
public Update(String version, File outputFile) {
URL url;
URLConnection connection = null;
try {
url = new URL("https://raw.githubusercontent.com/Luuuuuis/InstantVerify/master/version");
connection = url.openConnection();
} catch (IOException e1) {
e1.printStackTrace();
}
assert connection != null;
try (BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
String[] versionCode = in.readLine().split("&&");
if (!(versionCode[0].equalsIgnoreCase(version))) {
/*
* Download from URL given in version file
*/
if(versionCode[1] != null && !versionCode[1].equalsIgnoreCase("null")) {
Thread th = new Thread(() -> {
try {
URL downloadURL = new URL(versionCode[1]);
URLConnection urlConnection = downloadURL.openConnection();
urlConnection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36");
InputStream inputStream = urlConnection.getInputStream();
OutputStream outputStream = new FileOutputStream(outputFile);
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, length);
}
inputStream.close();
outputStream.close();
InstantVerify.version += " (outdated)";
我想 Java 中的内存映射存在问题,因为我的根服务器只有 2GB 的 RAM。我能做些什么来解决这个问题?谢谢你。
扬帆大鱼
阿晨1998
斯蒂芬大帝
随时随地看视频慕课网APP
相关分类