我编写了一个TCP客户端程序,它调用属性文件并从中获取值。当我第一次运行TCPClient时,它正常运行并将server.properties文件的所有数据值发送到服务器,但是一旦我尝试添加一个数据" data4"到server.properties文件我的项目得到一个" x"标记和server.properties文件中所做的更改没有反映,我得到错误:无法找到或加载类TCPClient。 我试图创建一个新项目,仍然相同,对属性文件所做的更改不反映。有人可以帮助我这个。提前致谢
public class TCPClient {
private static Socket socket;
public String getPropertyValues() throws IOException{
String result="";
Properties prop = new Properties();
String propFileName = "server.properties";
InputStream inputStream = getClass().getClassLoader().getResourceAsStream(propFileName);
prop.load(inputStream);
try
{
String host = prop.getProperty("host");
System.out.println(host);
int port = Integer.parseInt(prop.getProperty("port"));
System.out.println(port);
String data = prop.getProperty("data");
System.out.println(data);
InetAddress address = InetAddress.getByName(host);
socket = new Socket(address, port);
//Send the message to the server
OutputStream os = socket.getOutputStream();
OutputStreamWriter osw = new OutputStreamWriter(os);
BufferedWriter bw = new BufferedWriter(osw);
String sendMessage = data;
bw.write(sendMessage);
bw.flush();
System.out.println("Message sent to the server : "+sendMessage);
//Get the return message from the server
InputStream is = socket.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String message = br.readLine();
System.out.println("Message received from the server : " +message);
}
catch (Exception exception)
{
exception.printStackTrace();
}
finally
{
//Closing the socket
try
{
socket.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
return result;
}
public static void main(String[] args) throws IOException{
TCPClient properties = new TCPClient();
properties.getPropertyValues();
}
}
我有一个名称为server.properties
的属性文件data = data1
data2
data3
port = 3035
host = localhost
当我更改此属性文件的数据字段并保存时,项目将以" x"标记,当我尝试使用Run as - > JavaApplication运行TCPClient程序时,我弹出窗口
所需项目中存在错误
测试
继续启动?