问题描述
我尝试了各种方式上传多个文件。但是它要么上传1个文件,要么说无效文件。 2个文件存储在配置属性文件中。已经使用类加载器来获取文件
执行时,将2个文件路径复制到上载窗口,然后按打开后,将显示无效文件作为输出。
使用Robot类上传多个文件的代码段:
Robot robot = new Robot();
robot.setAutoDelay(3000);
File f1 = new File(prop.getProperty("filepath1"));
File f2 = new File(prop.getProperty("filepath2"));
String pi = f1.getName();
String pj = f2.getName();
System.out.println(pi);
System.out.println(pj);
ClassLoader classLoader = getClass().getClassLoader();
File file1 = new File(classLoader.getResource(pi).getFile());
File file2 = new File(classLoader.getResource(pj).getFile());
// String p = file1.getAbsolutePath() + " " + file2.getAbsolutePath();
String p = file1.getAbsolutePath() + "\n" + file2.getAbsolutePath();
System.out.println(p);
// System.out.println(p);
// Create instance of Clipboard class
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
StringSelection stringselection = new StringSelection(p);
// Copy the String to Clipboard
clipboard.setContents(stringselection,null);
// Use Robot class instance to simulate CTRL+C and CTRL+V key events :
robot.setAutoDelay(3000);
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_CONTROL);
// robot.setAutoDelay(500);
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
Thread.sleep(1000);
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)