Last active
March 26, 2019 08:22
-
-
Save zbo2018/9b731c249023832744712df9178be916 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
字符串转输入流 | |
new ByteArrayInputStream("abcd".getBytes()); | |
文件获取输入流 | |
file.getInputStream(); | |
代码获取web部署后resources目录资源文件内容 | |
InputStream in = this.getClass().getResourceAsStream("/customer_faq"); | |
String --> InputStream | |
ByteArrayInputStream stream = new ByteArrayInputStream(str.getBytes()); | |
File --> InputStream | |
InputStream in = new FileInputStream(file); | |
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(); | |
} | |
InputStream --> File | |
public void inputstreamtofile(InputStream ins,File 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(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment