resources下面的配置文件,application文件修改启动会实时加载新的内容
其他的文件属于静态文件,打包后会把文件打入jar里面,修改静态文件启动不会加载新的内容
Resource areacode = nre FileSystemResource("config" + File.separator + "areacode.json");
InputStream inputStream = areacode.getInputStream();
byte[] bytes = new byte[0];
bytes = new byte[inputStream.available()];
inputStream.read(bytes);
String str = new String(bytes);
String result = new BufferedReader(new InputStreamReader(inputStream))
.lines().collect(Collectors.joining(System.lineSeparator()));
String result = new BufferedReader(new InputStreamReader(inputStream))
.lines().parallel().collect(Collectors.joining(System.lineSeparator()));
Scanner s = new Scanner(inputStream).useDelimiter("\\A");
String str = s.hasNext() ? s.next() : "";
String resource = new Scanner(inputStream).useDelimiter("\\Z").next();
return resource;
StringBuilder sb = new StringBuilder();
String line;
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
while ((line = br.readLine()) != null) {
sb.append(line);
}
String str = sb.toString();
return str;
ByteArrayOutputStream result = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int length;
while ((length = inputStream.read(buffer)) != -1) {
result.write(buffer, 0, length);
}
String str = result.toString(StandardCharsets.UTF_8.name());
return str;
BufferedInputStream bis = new BufferedInputStream(inputStream);
ByteArrayOutputStream buf = new ByteArrayOutputStream();
int result = bis.read();
while(result != -1) {
buf.write((byte) result);
result = bis.read();
}
String str = buf.toString();
return str;
StringWriter writer = new StringWriter();
IOUtils.copy(inputStream, writer, StandardCharsets.UTF_8.name());
String str = writer.toString();
String str = IOUtils.toString(inputStream, "utf-8");
String str = CharStreams.toString(new InputStreamReader(inputStream, StandardCharsets.UTF_8));
String str = new String(ByteStreams.toByteArray(inputStream));
针对一个2MB的文件的输入流,多次执行测试如下(单位是毫秒):
方法十: 111
方法十一: 236
方法十二: 36
方法一: 36
方法二: 87
方法三: 66
方法四: 101
方法五: 178
方法六: 40
方法七: 21
方法八: 107
方法九: 31
从上述结果来看,方法七和方法九更好一些,而方法五和方法十一会更差一些。
InputStream is = new ByteArrayInputStream(str.getBytes());
InputStream targetStream = IOUtils.toInputStream(str, StandardCharsets.UTF_8.name());
InputStream targetStream =
new ReaderInputStream(CharSource.wrap(str).openStream(), StandardCharsets.UTF_8.name());