1. String --> inputstream
Inputstream string2inputstream (string Str ){
Bytearrayinputstream stream = new
Bytearrayinputstream (Str. getbytes ());
Return stream;
}
2. inputstream --> string
String inputstream2string (inputstream is ){
Bufferedreader in = new bufferedreader (New
Inputstreamreader (is ));
Stringbuffer buffer = new stringbuffer ();
String line = "";
While (line = in. Readline ())! = NULL ){
Buffer. append (line );
}
Return buffer. tostring ();
}
3. file --> inputstream
Inputstream in = new inputstream (New fileinputstream (File ));
The above line reports an error, and the new inputstream reports an error.
Write it as follows:
New fileinputstream (file)
4. inputstream --> File
Public void inputstreamtofile (inputstream INS, file ){
Outputstream OS = new fileoutputstream (File );
Int bytesread = 0;
Byte [] buffer = new byte [8192];
While (bytesread = ins. Read (buffer, 0, 8192 ))! =-1 ){
OS. Write (buffer, 0, bytesread );
}
OS. Close ();
INS. Close ();
}
From: http://blog.sina.com.cn/s/blog_3f7027fa0100mx1v.html