我编写了一个像这样的方法.但我想这应该进行重构.任何人都可以建议避免使用这多个if语句的最佳方法吗?
private String getMimeType(String fileName){
if(fileName == null) {
return "";
}
if(fileName.endsWith(".pdf")) {
return "application/pdf";
}
if(fileName.endsWith(".doc")) {
return "application/msword";
}
if(fileName.endsWith(".xls")) {
return "application/vnd.ms-excel";
}
if(fileName.endsWith(".xlw")) {
return "application/vnd.ms-excel";
}
if(fileName.endsWith(".ppt")) {
return "application/vnd.ms-powerpoint";
}
if(fileName.endsWith(".mdb")) {
return "application/x-msaccess";
}
if(fileName.endsWith(".rtf")) {
return "application/rtf";
}
if(fileName.endsWith(".txt")) {
return "txt/plain";
}
if(fileName.endsWith(".htm") || fileName.endsWith(".html")) {
return "txt/html";
}
return "txt/plain";
}
Run Code Online (Sandbox Code Playgroud)
我不能在这里使用switch-case,因为我的'条件'是java.lang.String.
是IKVM.NET使用Java代码或Java利布斯在.NET应用程序的好方法?
有没有人使用这个工具?还有替代品吗?是否有可能在基于COM的应用程序(如Visual Basic 6或经典ASP)中调用Java函数/代码?
我在使用SSHJ时遇到异常.
这是我实现它的方式:
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
final SSHClient ssh = new SSHClient();
ssh.loadKnownHosts();
ssh.connect("serverName");
try{
ssh.authPublickey("myUserId");
final Session session = ssh.startSession();
try{
final Command cmd = session.exec("net send myMachineName Hello!!!");
System.out.println(cmd.getOutputAsString());
System.out.println("\n Exit Status: "+cmd.getExitStatus());
}finally{
session.close();
}
}finally{
ssh.disconnect();
}
}
}
Run Code Online (Sandbox Code Playgroud)
但我得到以下异常:
Exception in thread "main" java.io.IOException: Could not load known_hosts
at net.schmizz.sshj.SSHClient.loadKnownHosts(SSHClient.java:528)
at SSHTEST.main(SSHTEST.java:25)
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
任何人都可以告诉我JDK7/8仍然可以使用jsr14目标选项javac吗?
说,
$ javac -source 1.5 -target jsr14 Hello.java
Run Code Online (Sandbox Code Playgroud) 在台湾,我们有一个名为"Unicode At One(UAO)"的字符编码,它是BIG-5的扩展,但Java和Android不支持.
代码页位于http://moztw.org/docs/big5/table/uao241-b2u.txt
我的问题是,如何使用此Charset构建具有字节数组数据的String对象?
我想我会扩展String类并在其中做一些事情,但我不知道如何创建一个新的Charset.
我必须从http://www.python.org/download/releases/2.5.4/安装Python 2.5.4,这是pcraster程序所必需的.
但是
对于x86处理器有三个python选择:python-2.5.4.msi
对于Win64-Itanium用户:python-2.5.4.ia64.msi
对于Win64-AMD64用户:python-2.5.4.amd64.msi
我知道我有Win64,但我不确定我的i7处理器是Itanium还是AMD?知识渊博的人能帮助我吗?
我正在尝试理解Eclipse类路径文件,特别是,我想知道这个:
JRE如何使用它(即JVM是直接读取这个xml文件,还是eclipse以某种方式将其提供给它的内部编译器)?
当我从IDE运行我的类时,如何解析复杂条目(如下面的常春藤路径)并将其合并到JVM ClassLoader中?
上下文:我有一个奇怪的错误,就是eclipse正在使用类的"错误"版本,而我的ivy/ant版本正在使用正确的版本,因此我希望使用Eclipse工具来更好地模仿我纯粹使用的类加载器建立.为了做到这一点,我想我将不得不看看Eclipse项目/类路径文件.
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="test"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="conf"/>
<classpathentry kind="con" path="org.apache.ivyde.eclipse.cpcontainer.IVYDE_CONTAINER/?ivyXmlPath=ivy.xml&confs=*"/>
<classpathentry kind="output" path="build"/>
</classpath>
Run Code Online (Sandbox Code Playgroud)