使用nio从sftp服务器读取文件时出错

t5zmwmid  于 2021-06-26  发布在  Java
关注(0)|答案(0)|浏览(338)

我正在尝试使用nio从sftp服务器读取一个引用链接的文件-https://github.com/gerardnico/niofs-sftp
https://examples.javacodegeeks.com/core-java/java-nio-read-file-example/ (第3.1点)
我的密码是

String encodedUsername = URLEncoder.encode(username, StandardCharsets.UTF_8.toString());
String encodedPassword = URLEncoder.encode(password, StandardCharsets.UTF_8.toString());
URI uri = URI.create("sftp://"+encodedUsername+":"+encodedPassword+"@"+host+":"+port+filePathOnServer);
Path myPath = Paths.get(uri);
try(BufferedReader reader = Files.newBufferedReader(myPath, Charset.forName("UTF-8"))){
String currentLine = null;
while((currentLine = reader.readLine()) != null)
           {//while there is content on the current line
                    System.out.println(currentLine); // print the current line
                  }
            }

错误日志

java.nio.file.FileSystemNotFoundException: Provider "sftp" not installed
    at java.nio.file.Paths.get(Paths.java:147)
    at com.aexp.grt.mbx.helper.OperationsRelatedToFile.readFileAndCalculateFillRateForColumns(OperationsRelatedToFile.java:277)
    at com.aexp.grt.mbx.controller.CalculateFillRateOfFileController.calculateFillRateOfColumns(CalculateFillRateOfFileController.java:150)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:878)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:792)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:652)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.springframework.web.filter.CorsFilter.doFilterInternal(CorsFilter.java:92)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
    at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:204)
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:183)
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:358)
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:271)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
- - -

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题