Java에서 문자열을 InputStreamReader로 변환하려면 어떻게 해야 하나요?
어떻게 변환해야 합니까?String가치로 삼다.InputStreamReader?
또한 ByteArrayInputStream은 다음과 같은 기능을 수행합니다.
InputStream is = new ByteArrayInputStream( myString.getBytes( charset ) );
그런 다음 판독기로 변환:
InputStreamReader reader = new InputStreamReader(is);
아파치 커먼즈도 찾았어요IOUtilsclass, so:
InputStreamReader isr = new InputStreamReader(IOUtils.toInputStream(myString));
Input Stream Reader를 사용해야 합니까?StringReader를 사용하는 것은 어떻습니까?
그렇지 않으면 StringBufferInputStream을 사용할 수 있지만 문자 변환 문제로 인해 권장되지 않습니다(이 때문에 StringReader를 사용해야 합니다).
@Dan과 같은 질문입니다.StringReader가 아닌 이유는 무엇입니까?
InputStreamReader여야 하는 경우:
String charset = ...; // your charset
byte[] bytes = string.getBytes(charset);
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
InputStreamReader isr = new InputStreamReader(bais);
A를 취득하려고 합니까?)Reader기능성InputStreamReader, 또는 b)InputStream기능성InputStreamReaderb)는 취득할 수 없습니다. InputStreamReader가 아니다InputStream.
의 목적InputStreamReader를 가져가기 위해서InputStream- 바이트 소스 - 바이트를 문자 형식으로 디코딩합니다.Reader데이터는 이미 chars(원래 문자열)로 되어 있습니다.String을 바이트로 인코딩하고 바이트를 chars로 디코딩하는 것은 장황한 조작입니다.
만약 당신이 그것을 얻으려고 한다면Reader정보원을 벗어나서StringReader.
만약 당신이 그것을 얻으려고 한다면InputStream(바이트만 제공), Apache Commons 사용IOUtils.toInputStream(..)여기 다른 답변에서 제시된 바와 같이요.
선인장을 맛볼 수 있습니다.
InputStream stream = new InputStreamOf(str);
그럼, 필요한 경우Reader:
Reader reader = new ReaderOf(stream);
언급URL : https://stackoverflow.com/questions/247161/how-do-i-turn-a-string-into-a-inputstreamreader-in-java
'programing' 카테고리의 다른 글
| 비동기 작업이 완료되기 전의 Vuex 액세스 상태 (0) | 2022.07.23 |
|---|---|
| 변수 선언은 비용이 많이 드나요? (0) | 2022.07.23 |
| 동일한 API 함수를 호출하는 두 개의 vue 구성 요소 (0) | 2022.07.16 |
| VueJ에서 작동하지 않는 Vuex 저장소 어레이에 푸시s (0) | 2022.07.16 |
| 체크박스에 vue-fontawesome을 사용할 수 있습니까? (0) | 2022.07.16 |