java怎么读取linux服务器上的world文档,多谢了

2024-11-17 13:42:00
推荐回答(2个)
回答1:

给你一段代码你试试(远程访问ftp):前提需要ftpClient的jar包
public static void main(String[] args) {
FileOutputStream fileOutputStream = null; FTPClient ftpClient = null; try { ftpClient = new FTPClient(); String host = "192.168.100.1"; int port = 21; String username = "root"; String password = "handinfo"; String remoteDir = "/share_oracle/resource/201206/"; String fileName = "20120615110653.doc"; ftpClient.connect(host,port); ftpClient.setControlEncoding("UTF-8"); ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE); ftpClient.login(username, password); File saveFile = new File("d:/" + fileName); fileOutputStream = new FileOutputStream(saveFile); ftpClient.retrieveFile(remoteDir + fileName, fileOutputStream); } catch (Exception e) { e.printStackTrace(); } finally { try { if (fileOutputStream != null) { fileOutputStream.close(); fileOutputStream = null; } if (ftpClient != null && ftpClient.isConnected()) { ftpClient.disconnect(); ftpClient = null; } } catch (IOException e) { e.printStackTrace(); } }

回答2:

在哪都一样啊.路径写对了就行了..