try {
int count;
URL url = new URL("http://www.exampleserver.com/file names.txt");
URLConnection connection = url.openConnection();
connection.setReadTimeout(TIMEOUT_CONNECTION);
connection.setConnectTimeout(TIMEOUT_SOCKET);
connection.setRequestProperty("connection", "close");
connection.connect();
int lengthOfFile = connection.getContentLength();
long total = 0;
InputStream input = new BufferedInputStream(url.openStream());
OutputStream output = new FileOutputStream(BasindaOneCikanDosyalar);
byte data[] = new byte[40096];
while ((count = input.read(data)) != -1) {
total += count;
output.write(data, 0, count);
}
output.flush();
output.close();
input.close();
} catch (IOException e1) {
e1.printStackTrace();
}
나는이 알고리즘을 사용하고 있지만 파일 이름에 공백이 포함 된 경우, 나는 java.io.FileNotFoundException 및 getResponseCode 가지고 : 400합니다.파일 이름에 공백이 포함 된 경우 어떻게 안드로이드에 URLConnection과 함께 다운로드 할 수 있습니까?
다운로드 URL에 대한 라이브러리 또는 다른 알고리즘이 있습니까?
URI uri = new URI("http", "www.exampleserver.com", "/file names.txt", null);
URL url = uri.toURL();
정말 대단합니다. 시도해 보겠습니다. 감사합니다. – massaimara98
감사합니다. 덕분에 시험을 보았습니다. 계속 작업 할 수 있습니다. – massaimara98
정확하지 않습니다. 그것의 이름에도 불구하고,'URLEncoder'는'% 20'에 대한 조정 후 여기에서 알 수 있듯이, URL이 아닌 인수 이름과 값을 인코딩하기위한 것입니다. 올바른 기술은 @ PeterPeiGuo의 답변에 나와 있습니다. – EJP