java IO
Last updated on November 22, 2024 pm
🧙 Questions
☄️ Ideas
创建文件夹
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
if(!outputFile.getParentFile().exists()) {
if(!outputFile.getParentFile().mkdirs()) {
log.debug(
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
}
}
@GetMapping("/demo")
public void demo() {
try {
Path file = Paths.get("D://test").resolve("test.log");
Resource resource = new UrlResource(file.toUri());
if (!(resource.exists() || resource.isReadable())) {
System.out.println("Flase");
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
if(!outputFile.getParentFile().exists()) {
if(!outputFile.getParentFile().mkdirs()) {
log.debug(
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
}
} }
InputStream is = resource.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
StringBuilder logBuilder = new StringBuilder("");
String data = null;
while ((data = br.readLine()) != null) {
logBuilder.append(data).append("\n");
}
br.close();
isr.close();
is.close();
System.out.println(logBuilder.toString().contains("OK"));
} catch (IOException e) {
e.printStackTrace();
}
}
🔗 Links
java IO
https://ispong.isxcode.com/spring/java/java IO/