我需要在远程计算机上创建一个文件夹。出于测试目的,我正在尝试使用我的机器IP地址在我自己的机器上创建文件夹。我的Ubuntu机器IP地址是XX.X.X.XX.我想使用以下java代码片段在我的主目录上创建一个名为E book的文件夹。但以下内容并未创建文件夹。请帮忙。
let gameId = 'myGameId';
let chatRoomId = 'myChatRoomId';
requester.sendRequest(
'POST', '/createGame', {gameId: gameId});
requester.sendRequest(
'POST', '/createChatRoom', {gameId: gameId, chatRoomId: chatRoomId});
的System.out.println(文件夹);
答案 0 :(得分:1)
您可以通过在java中执行进程来完成此任务:
BufferedReader stdError = null;
try
{
// change the you and server accordingly
String command = "ssh you@server \"mkdir /home/name/EBook\"";
Process p = Runtime.getRuntime().exec(command);
stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
// read any errors from the attempted command
System.out.println("Here is the standard error of the command (if any):\n");
String s = null;
while ((s = stdError.readLine()) != null)
{
System.out.println(s);
}
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{
if (stdError != null)
{
try
{
stdError.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}