修改文件上传io报错问题

master
whb 8 months ago
parent 13307631b8
commit 7593f67fdf

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

Loading…
Cancel
Save