我正在尝试创建一个web服务,只要更新某个文件夹就会发送数据。我使用的是一个接口filelistener。 问题是我的接口方法没有执行我的代码是 接口方法filechanged未执行
public class SendFile implements FileListener
{
FileMonitor monitor=new FileMonitor(1000);
private static String Final;
private static final String FILE_PATH = "C:\\Users\\298637\\Desktop\\Test1.xml";
private InputStream is;
public void Send(String msg)
{
Final=msg;
}
@GET
@Path("/get")
@Produces("application/xml")
public InputStream getFile() {
try
{
//FileMonitor monitor=new FileMonitor(1000);
monitor.addFile(new File ("D:/uploaded"));
monitor.addListener(new Test());
System.out.println(Final);
is = new FileInputStream(FILE_PATH);
ResponseBuilder response = Response.ok((Object) is);
response.header("Content-Disposition","attachment; filename=newfile.xml");
//while(!false);
}
catch (Exception e)
{
e.printStackTrace();
}
return is;
}
class Test implements FileListener
{
public void fileChanged (File file)
{
System.out.println ("File changed: " + file);
monitor.Receive(file);
}
}
}
为了得到结果,任何人都可以告诉我应该改变什么