2016-10-03 1 views
-1

읽기 및 쓰기 동작 : IP = 172.16.20.1 경로의/etc/설정에게 있습니다원격 파일 내가 예를 들어 내 원격 시스템에서 파일을 .txt로 한

내가 자바

에서이 파일에 연결해야 할 방법

여기 내 코드입니다.

String path = "http://172.16.20.1/etc/config/file.txt"; 

URL url = new URL(path); 
URLConnection yc = url.openConnection(); 
BufferedReader br = new BufferedReader(new InputStreamReader (yc.getInputStream())); 

하지만 난 HTTPS 내가 모르는 뭔가가

M이 파일 file.txt 파일이있는/등 폴더를 사용하는 경우 내가 HTTP javax.net.ssl.SSLHandshakeException을 받고 &과 경로를 사용하면 파일이 아닌 예외를 받고 있어요 (리눅스)이 공유지-VFS를 사용하여 원격 컴퓨터에서 파일을 읽기 위해, 자사의 작동 잘

+0

geeting 파일을 찾을 수없는 예외 –

+0

java.net.ConnectException 점점 : FTP 프로토콜을 사용하는 경우 연결이 거부되었습니다. –

답변

0

확인

public static void readRemoteManifestFile(String ipAddress,String filePath,String username,String password){ 

    //filePath="/usr/local/tomcat/webapps/abc/test/NavigationPanel.html"; 

    try { 

     StandardFileSystemManager manager = new StandardFileSystemManager(); 
     manager.init(); 

     FileObject remoteFile = manager.resolveFile(createConnectionString(ipAddress, username,password, 
       filePath), createDefaultOptions()); 
     if(!remoteFile.exists()){ 
      System.out.println(filePath+": no such file"); 
     }else{ 
      Reader  inputStreamReader = new InputStreamReader( remoteFile.getContent().getInputStream()); 
      char c; 
       int i; 
      while((i=inputStreamReader.read())!=-1) 
      { 
       // int to character 
       c=(char)i;    
       // print char 
       System.out.println("Character Read: "+c); 
      } 
     } 

    } catch (Exception e) { 
     System.out.println("Failed to read for "+ 
       filePath+": "+e); 
     System.out.println("Failed to read for "+ 
       filePath+": "+e.getMessage()); 

    } 


} 
public static String createConnectionString(String hostName, 
     String username, String password, String remoteFilePath) { 
    return "sftp://" + username + ":" + password + "@" + hostName + "/" + remoteFilePath; 
} 

public static FileSystemOptions createDefaultOptions() 
     throws FileSystemException { 
    FileSystemOptions opts = new FileSystemOptions(); 
    SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(
      opts, "no"); 
    SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, false); 
    SftpFileSystemConfigBuilder.getInstance().setTimeout(opts, 10000); 
    return opts; 
} 

}

관련 문제