线程" main"中的例外情况java.net.MalformedURLException:没有协议:

时间:2013-12-09 18:04:18

标签: java

我尝试将大量文件从经过身份验证的目录移动到服务器目录,但是收到此错误

线程“main”中的异常java.net.MalformedURLException:无协议:/PGJ/portal/Importador_Documentos_Financeiro/FILES/FINANCEIRO/RF255677.pdf     在java.net.URL。(未知来源)     在jcifs.smb.SmbFile。(SmbFile.java:446)     在importador_documentos.Main.main(Main.java:82)

我尝试了很多东西,但没有解决这个问题,请有人帮帮我吗?

public class Main {
    public static String Pasta_Financeiro = System.getProperty("user.dir") +
            File.separatorChar + "FILES" + File.separatorChar +
            "FINANCEIRO" + File.separatorChar;

    public static void main(String[] args) throws ClassNotFoundException,
            SQLException,
            FileNotFoundException,
            IOException,
            AuthenticationException
    {
        try{
            jcifs.Config.registerSmbURLHandler();
            NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("cabanellos.local", "deivisson.sedrez", "password");
            String path = "smb://fsct/scanpr$/";
            SmbFile sFile = new SmbFile(path.toString(), auth);        
            SmbFile[] varTeste = sFile.listFiles();
            SmbFile dir = new SmbFile(path.toString(), auth);
            System.out.println(dir.getDate());
            URL site;
            for(int i=0;i<varTeste.length;i++){
                if(varTeste[i].isFile()){                                        
                    //site = new URL((Pasta_Financeiro + varTeste[i].getName()).toString()); 
                    SmbFile dest = new SmbFile ("//"+Pasta_Financeiro + varTeste[i].getName());
                    dir.copyTo(dest);
                }
            }    
//rest of content...
}

1 个答案:

答案 0 :(得分:2)

变化:

SmbFile dest = new SmbFile ("//"+Pasta_Financeiro + varTeste[i].getName());

为:

SmbFile dest = new SmbFile ("file:///"+Pasta_Financeiro + varTeste[i].getName());

请参阅wikipedia file URI scheme