修改文件上传io报错问题

master
whb 8 months ago
parent 13307631b8
commit 7593f67fdf

@ -176,8 +176,10 @@ public class JupyterhubController {
String filepath = "/etc/jupyterhub/data/" + caseName + "/data/"; String filepath = "/etc/jupyterhub/data/" + caseName + "/data/";
File directory = new File(filepath);
if (!directory.exists()) {
directory.mkdirs();
}
//设置数据文件 //设置数据文件
if (dataFile != null && !dataFile.isEmpty()) { if (dataFile != null && !dataFile.isEmpty()) {
@ -186,48 +188,48 @@ public class JupyterhubController {
iFileUtil.uploadResource(file, filepath, null); iFileUtil.uploadResource(file, filepath, null);
try { // try {
// 创建 chmod 命令以递归方式修改权限 // // 创建 chmod 命令以递归方式修改权限
String[] command = {"chmod", "-R", "777", filepath}; // String[] command = {"chmod", "-R", "777", filepath};
// 创建一个新的进程来执行Python代码 // // 创建一个新的进程来执行Python代码
Process process = Runtime.getRuntime().exec(command); // Process process = Runtime.getRuntime().exec(command);
//
//
// 获取进程的输入流 // // 获取进程的输入流
BufferedReader inputStream = new BufferedReader(new InputStreamReader(process.getInputStream())); // BufferedReader inputStream = new BufferedReader(new InputStreamReader(process.getInputStream()));
//
// 获取进程的输出流 // // 获取进程的输出流
BufferedReader errorStream = new BufferedReader(new InputStreamReader(process.getErrorStream())); // BufferedReader errorStream = new BufferedReader(new InputStreamReader(process.getErrorStream()));
//
//
// 读取Python代码的输出 // // 读取Python代码的输出
String line; // String line;
StringBuilder output = new StringBuilder(); // StringBuilder output = new StringBuilder();
while ((line = inputStream.readLine()) != null) { // while ((line = inputStream.readLine()) != null) {
output.append(line).append("\n"); // output.append(line).append("\n");
} // }
//
// 读取Python代码的错误信息 // // 读取Python代码的错误信息
StringBuilder errors = new StringBuilder(); // StringBuilder errors = new StringBuilder();
while ((line = errorStream.readLine()) != null) { // while ((line = errorStream.readLine()) != null) {
errors.append(line).append("\n"); // errors.append(line).append("\n");
} // }
//
// 等待进程执行完成 // // 等待进程执行完成
int exitCode = process.waitFor(); // int exitCode = process.waitFor();
//
if (exitCode == 0) { // if (exitCode == 0) {
// 执行成功输出Python代码的结果 // // 执行成功输出Python代码的结果
System.out.println("权限修改成功!"); // System.out.println("权限修改成功!");
//
} else { // } else {
// 执行失败,输出错误信息 // // 执行失败,输出错误信息
System.err.println("权限修改失败了!\n" + errors.toString()); // System.err.println("权限修改失败了!\n" + errors.toString());
//
} // }
} catch (IOException | InterruptedException e) { // } catch (IOException | InterruptedException e) {
e.printStackTrace(); // e.printStackTrace();
} // }
} }

Loading…
Cancel
Save