简体   繁体   English

从Windows OS到Java中的Unix文件迁移

[英]file treansfer from windows OS to unix in Java

I create a pdf file in runtime (in Windows OS). 我在运行时(在Windows OS中)创建pdf文件。 I need to copy it to another location, it might be on UNIX or windows. 我需要将其复制到另一个位置,它可能在UNIX或Windows上。 Is there a java class I can do it with? 我可以使用Java类吗? and how? 如何? Thanks. 谢谢。

URL url = 
    new URL("ftp://username:password@ftp.localhost/file.pdf;type=i");
URLConnection con = url.openConnection();
BufferedInputStream in = 
    new BufferedInputStream(con.getInputStream());
FileOutputStream out = 
    new FileOutputStream("C:\\file.pdf");

int i = 0;
byte[] bytesIn = new byte[1024];
while ((i = in.read(bytesIn)) >= 0) {
    out.write(bytesIn, 0, i);
}
out.close();
in.close();

If you place the file in the directory space of an FTP server (on your Windows machine), you can use URLConnection in a Java app on a remove client to fetch it. 如果将文件放在FTP服务器的目录空间中(在Windows计算机上),则可以在Remove Client上的Java应用程序中使用URLConnection来获取文件。 See @Mohamed Saligh's answer for example code. 有关示例代码,请参见@Mohamed Saligh的答案。 (The key is to use an "ftp:" URL, and to force the transfer type to be binary.) (关键是使用“ ftp:” URL,并将传输类型强制为二进制。)

Other resources that may help include the Apache Commons FTP Client library , and the Apache Mina FTP server . 其他可能有用的资源包括Apache Commons FTP客户端库Apache Mina FTP服务器 The FTP client library would allow you to "push" the file to an FTP server on Windows / UNIX ... as well as "pull" it as URLConnection does. FTP客户端库将允许您将文件“推送”到Windows / UNIX上的FTP服务器上,也可以像URLConnection一样“拉”该文件。

There are various other Java FTP clients, servers and libraries "floating around the interwebs" ... according to a certain well-known search engine :-). 根据某些知名的搜索引擎:-),还有其他各种Java FTP客户端,服务器和库“在Internet周围浮动”...。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM