我正在为我的CSVreader创建一个Junit测试文件.我正在阅读CSV文件的内容并将内容写入另一个文件.我想使用diff实用程序比较它们,我想使用diff的退出状态来知道内容是否相同.一般是$?给出退出状态,但我不知道如何捕获它并在我的代码中使用它.谁可以在这方面帮助我?
这就是我的代码看起来的样子
boolean hasSameContents = false;
command="diff "+mp.get("directory")+"/"+fileName+" "+mp.get("outdir")+"/"+fileName;
p= Runtime.getRuntime().exec(command);
p.waitFor();
Run Code Online (Sandbox Code Playgroud)
在此之后我想获得退出状态并在if这样的条件下使用它
if(exit_status==0)
hasSameContents = true;
else
hasSameContents = false;
Run Code Online (Sandbox Code Playgroud)
甚至其他建议也很受欢 :)
我有一个通用的独立JMS应用程序,它与以下JMS提供程序WebSphere,HornetQ和ActiveMq一起使用.我将Context.INITIAL_CONTEXT_FACTORY和Context.PROVIDER_URL作为参数传递给我的应用程序,并通过执行类似这样的操作创建一个命名上下文
Properties environmentParameters = new Properties();
environmentParameters.put(Context.INITIAL_CONTEXT_FACTORY, property.context);
environmentParameters.put(Context.PROVIDER_URL, property.provider);
namingContext = new InitialContext(environmentParameters);
Run Code Online (Sandbox Code Playgroud)
并使用此上下文进行对象查找.
我知道RabbitMQ不是JMS提供者,因此它没有InitialContext类或Provider URL,但它提供了一个JMS Client,它是符合JMS规范的Java客户端的抽象.RabbitMQ的JMS客户端文档有一个例子,它将JNDI中的对象定义为资源配置,作为Web应用程序的一部分,但我完全无法弄清楚如何为我的独立应用程序执行类似操作,该应用程序使用JMS基于JNDI提供程序创建命名上下文客户端的依赖项或从可用的依赖项中创建InitialContext.
那么有人可以说明如何做到这一点?希望我的问题很明确.
我有一个应用程序,其中将文件添加到目录中时,WatchService会检测到该文件,并将该文件添加到文件列表中以进行进一步处理。这是我的代码
public void run() {
/*
* Goes in an infinite loop
*/
while(!finished) {
/*
* Get a watch key, poll() returns a queued key
* if no queued key, this method waits until the specified time.
*/
WatchKey key;
try {
key = watcher.poll(eofDelay,TimeUnit.MILLISECONDS);
} catch (InterruptedException x) {
return;
}
Path dir = keys.get(key);
if (dir == null) {
continue;
}
Path child=null;
/*
* Fetching the list of watch events from
* pollEvents(). There are four …Run Code Online (Sandbox Code Playgroud)