任何人都可以解释我以下代码有什么问题吗?我尝试了不同的主机,FTPClientConfigs,它可以通过firefox/filezilla正确访问...问题是我总是得到空文件列表,没有任何异常(files.length == 0).我使用与Maven一起安装的commons-net-2.1.jar.
FTPClientConfig config = new FTPClientConfig(FTPClientConfig.SYST_L8);
FTPClient client = new FTPClient();
client.configure(config);
client.connect("c64.rulez.org");
client.login("anonymous", "anonymous");
client.enterRemotePassiveMode();
FTPFile[] files = client.listFiles();
Assert.assertTrue(files.length > 0);
Run Code Online (Sandbox Code Playgroud) 这是代码
BufferedWriter bw = new BufferedWriter(new FileWriter("test.txt"));
try {
bw.write("test");
} finally {
IOUtils.closeQuietly(bw);
}
Run Code Online (Sandbox Code Playgroud)
安全与否?据我所知,当我们关闭BufferedWriter时,它会将其缓冲区刷新到底层流,并可能因错误而失败.但IOUtils.closeQuietly API表示将忽略任何异常.
由于IOUtils.closeQuietly,数据丢失是否有可能被忽视?
springframework.beans.BeanUtils复制对象非常有用,我经常使用"ignoreProperties"选项.但是,有时我只想复制特定对象(基本上,与"忽略属性"相反).有谁知道我该怎么做?任何帮助将不胜感激.
import org.springframework.beans.BeanUtils;
public class Sample {
public static void main(String[] args) {
DemoADto demoADto = new DemoADto();
demoADto.setName("Name of Demo A");
demoADto.setAddress("Address of Demo A");
DemoBDto demoBDto = new DemoBDto();
// This is "ignoreProperties" option
// But I want to know how I can copy only name field by using BeanUtils or something.
BeanUtils.copyProperties(demoADto, demoBDto, new String[] {"address"});
System.out.println(demoBDto.getName());
System.out.println(demoBDto.getAddress());
}
}
public class DemoADto {
private String name;
private String address;
public String getName() {
return name; …Run Code Online (Sandbox Code Playgroud) 我想尝试使用Apache Commons CLI,并认为一个好的起点是它的网页上的"使用"部分.
http://commons.apache.org/proper/commons-cli/usage.html
现在,这个例子建议创建一个DefaultParser,但是我能找到的最接近的声音是BasicParser.这是用的东西,我错过了什么吗?
在FileUtils.writeStringToFile(fileName, text)Apache的共享I/O功能将覆盖在一个文件中以前的文本.我想将数据附加到我的文件中.有什么方法可以使用Commons I/O吗?我可以使用普通BufferedWriter的Java 来做到这一点,但我很好奇使用Commons I/O.
这两个库之间的任何关系或区别.
Apache Commons HttpClient库是否支持Gzip?我们想在我们的Apache服务器上使用enable gzip压缩来加速客户端/服务器通信(我们有一个php页面,允许我们的Android应用程序与服务器同步文件).
java gzip apache-commons apache-commons-httpclient apache-httpclient-4.x
我正在用Java编写命令行应用程序,我选择了Apache Commons CLI来解析输入参数.
假设我有两个必需的选项(即-input和-output).我创建新的Option对象并设置所需的标志.现在一切都很好.但我有第三个,不是必需的选项,即.-救命.使用我提到的设置,当用户想要显示帮助时(使用-help选项),它表示需要"-input和-output".有没有办法实现这个(通过Commons CLI API,而不是简单的if(!hasOption)抛出新的XXXException()).
java command-line-interface apache-commons apache-commons-cli
对于CLI,我需要传入一个int数组作为特定选项的输入.
示例 - 以下命令将接受customerIds数组并执行某些操作.
myCommand -c 123 124 125
我使用Apache commons CLI实现了CLI,我使用getOptionValues("c")来检索此数组.
问题是,这只返回数组中的第一个元素,即[123],而我期望它返回[123,124,125].
我的代码的精简版本,
CommandLine cmd;
CommandLineParser parser = new BasicParser();
cmd = parser.parse(options, args);
if (cmd.hasOption("c")){
String[] customerIdArray = cmd.getOptionValues("c");
// Code to parse data into int
}
Run Code Online (Sandbox Code Playgroud)
有人可以帮我在这里找出问题吗?
在我的应用程序中,我使用的是apache commons Lang v.3.一个需要的图书馆给我一个
java.lang.ClassNotFoundException: org.apache.commons.lang.StringUtils
Run Code Online (Sandbox Code Playgroud)
在commmon.lang和commons.lang3之间是否有构建转换,或者我必须添加两个lang库?
apache-commons ×10
java ×10
apache ×1
file-io ×1
ftp-client ×1
gzip ×1
httpclient ×1
jar ×1
spring ×1
spring-mvc ×1