"함수 url get contents()"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
 
(다른 사용자 한 명의 중간 판 2개는 보이지 않습니다)
1번째 줄: 1번째 줄:
[[분류: URL]]
[[분류: URL]]
{{DISPLAYTITLE|함수 url_get_contents()}}
;함수 url_get_contents()
;함수 url_get_contents()


==Java==
==Java==
[[분류: Java]]
[[분류: Java]]
<source lang='java'>
<syntaxhighlight lang='java'>
private static String url_get_contents(String urlstr) {
private static String url_get_contents(String urlstr) {
String content = null;
String content = null;
try {
try {
    URL url = new URL(urlstr);
URL url = new URL(urlstr);
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.getResponseCode();
connection.getResponseCode();
    InputStream stream = connection.getErrorStream();
InputStream stream = connection.getErrorStream();
    if (stream == null) {
if (stream == null) stream = connection.getInputStream();
        stream = connection.getInputStream();
Scanner scanner = new Scanner(stream);
    }
scanner.useDelimiter("\\Z");
    try (Scanner scanner = new Scanner(stream)) {
content = scanner.next();
        scanner.useDelimiter("\\Z");
scanner.close();
        content = scanner.next();
}
    }
catch (MalformedURLException e) { e.printStackTrace(); }
} catch (IOException e) { e.printStackTrace(); }
catch (IOException e) { e.printStackTrace(); }
return content;
return content;
}
}
</source>
</syntaxhighlight>


==같이 보기==
==같이 보기==
* [[함수 file_get_contents()]]
* [[함수 file_get_contents()]]

2020년 11월 2일 (월) 02:49 기준 최신판

함수 url_get_contents()

1 Java[ | ]

private static String url_get_contents(String urlstr) {
	String content = null;
	try {
		URL url = new URL(urlstr);
		HttpURLConnection connection = (HttpURLConnection) url.openConnection();
		connection.getResponseCode();
		InputStream stream = connection.getErrorStream();
		if (stream == null) stream = connection.getInputStream();
		Scanner scanner = new Scanner(stream);
		scanner.useDelimiter("\\Z");
		content = scanner.next();
		scanner.close();
	}
	catch (MalformedURLException e) { e.printStackTrace(); }
	catch (IOException e) { e.printStackTrace(); }
	return content;
}

2 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}