가능한 중복 :
How do I convert a String to an InputStream in Java?자바에서 String을 inputStream으로 읽으려면 어떻게해야합니까?
이 어떻게 자바에서의 InputStream로 문자열을 읽을 수 있습니까?
String say = "say"
을 InputStream/InputSource로 변환 할 수 있기를 원합니다. 어떻게해야합니까?
가능한 중복 :
How do I convert a String to an InputStream in Java?자바에서 String을 inputStream으로 읽으려면 어떻게해야합니까?
이 어떻게 자바에서의 InputStream로 문자열을 읽을 수 있습니까?
String say = "say"
을 InputStream/InputSource로 변환 할 수 있기를 원합니다. 어떻게해야합니까?
public class StringToInputStreamExample {
public static void main(String[] args) throws IOException {
String str = "This is a String ~ GoGoGo";
// convert String into InputStream
InputStream is = new ByteArrayInputStream(str.getBytes());
// read it with BufferedReader
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
br.close();
}
}
+1 독자의 좋은 사용 : – MadProgrammer
-1'str.getBytes()'에'Charset'을 지정하지 않았습니다. –
뭔가 같은 ...
InputStream is = new ByteArrayInputStream(sValue.getBytes());
작동합니다 ...
당신은 ByteArrayInputStream
를 사용할 수 있습니다. InputStream
메서드를 사용하여 byte[]
의 요소를 읽습니다.
InputStream
MadProgrammer에 대한 답변이 있습니다. Reader
가 정상이라면
, 당신은 사용할 수 있습니다 : 당신은 그냥 구글 경우
Reader r = StringReader(say);
이 꽤 잘 설명되어 있습니다. –