gpt4 book ai didi

java - cmd “class not found”

转载 作者:行者123 更新时间:2023-12-03 11:54:55 25 4
gpt4 key购买 nike

我正在尝试使用套接字将两台计算机连接在一起,并且在cmd中键入java Client时不断出现此错误。我设置了javac的路径
我导航到我的项目。我可以使用javac Client.java进行编译,但无法使用Java运行它。
请参阅所附图片中的错误。

enter image description here

我会附上客户代码。

public class Client {

ObjectInputStream Sinput; // to read the socket
ObjectOutputStream Soutput; // towrite on the socket
Socket socket;

// Constructor connection receiving a socket number
Client(int port) {
// we use "localhost" as host name, the server is on the same machine
// but you can put the "real" server name or IP address
try {
socket = new Socket("192.168.43.115", port);
}
catch(Exception e) {
System.out.println("Error connectiong to server:" + e);
return;
}
System.out.println("Connection accepted " +
socket.getInetAddress() + ":" +
socket.getPort() + "\n");

/* Creating both Data Streams */
try
{
Sinput = new ObjectInputStream(socket.getInputStream());
Soutput = new ObjectOutputStream(socket.getOutputStream());
}
catch (IOException e) {
System.out.println("Exception creating new Input/output Streams: " + e);
return;
}
// my connection is established
String test = new String ();
test = "What is the date & time now ??";
// send the question (String) to the server
System.out.println("Client sending \"" + test + "\" to serveur\n");
try {
Soutput.writeObject(test);
Soutput.flush();
}
catch(IOException e) {
System.out.println("Error writting to the socket: " + e);
return;
}
// read back the answer from the server
String response;
try {
response = (String) Sinput.readObject();
System.out.println("Read back from server: " + response);
}
catch(Exception e) {
System.out.println("Problem reading back from server: " + e);
}

try{
Sinput.close();
Soutput.close();
}
catch(Exception e) {}

}
public static void main(String[] args) {
new Client(1500);
}

}

最佳答案

看看这个问题/答案How do I run a Java program from the command line on Windows?

首先,您需要使用“javac”将.java文件编译成.class文件,然后再使用“java”运行它

关于java - cmd “class not found”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49876489/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com