首页 > 代码库 > JAVA文件拷贝(Windows & Linux)
JAVA文件拷贝(Windows & Linux)
package unsorted;import java.io.File;import java.io.FileOutputStream;import java.io.InputStream;import java.io.OutputStream;public class CopyFile { private static String osname = System.getProperties().getProperty("os.name"); public static void copyfile() { if (osname.contains("Windows")) { File f = new File("C:/Windows/System32/jnetpcap.dll"); if(! f.exists()) { System.out.println("copy jnetpcap.dll to system32 folder"); InputStream instream = CopyFile.class.getResourceAsStream("/jnetpcap.dll"); OutputStream out = null; try { out = new FileOutputStream(new File("C/Windows/System32/jnetpcap.dll")); int read = 0; byte[] bytes = new byte[2048]; while((read = instream.read(bytes)) != -1) { out.write(bytes, 0, read); } out.flush(); instream.close(); out.close(); } catch (Exception e) { e.printStackTrace(); System.out.println("copy jnetpcap.dll failed"); } } } else if(osname.equalsIgnoreCase("Linux")) { File f = new File("/usr/lib/libjnetpcap.so"); if(! f.exists()) { System.out.println("copy libjnetpcap.so to /usr/lib/ folder"); InputStream instream = CopyFile.class.getResourceAsStream("/libjnetpcap.so"); OutputStream out = null; try { out = new FileOutputStream(new File("/usr/lib/jnetpcap.so")); int read = 0; byte[] bytes = new byte[2048]; while((read = instream.read(bytes)) != -1) { out.write(bytes, 0, read); } out.flush(); instream.close(); out.close(); } catch (Exception e) { e.printStackTrace(); System.out.println("copy jnetpcap.so failed"); } } } }}
JAVA文件拷贝(Windows & Linux)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。