-4
我遇到textbox
问题。我试图将一个文件复制到数组列表中并将其传送到另一个文件夹。如何从java中的文本框中获取字符串
当我使用这个:String strSource = "D:\\New folder\\";
String strDestination = "D:\\New folder\\Another Folder\\";
它复制里面的文件,但是当我将其更改为String strSource = txtSource.getText();
并同与目标没有错误,但只有catch
但目标文件夹为空。如果你们对我的问题感到困惑,我会尽力向你解释。
复制方法
public void copyFiles(String source, String destination){
try {
File fileFrom = new File(source);
File fileTo = new File(destination);
Files.copy(fileFrom.toPath(), fileTo.toPath());
} catch (IOException e) {
// e.printStackTrace();
MessageBox msgBox = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK);
msgBox.setText("Error");
msgBox.setMessage("File is AlreadyExist."); //where this is the one catching..
msgBox.open();
}
}
复制按钮
String strSource = new String(txtSource.getText());
String strDestination = new String (txtDestination.getText());
try {
ArrayList<String> list = readConfigFileList(ConstantVariables.SPECIFIC_FILE_LIST);
for (String strList : list) {
copyFiles(strSource + strList, strDestination + strList);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
请[编辑]你的问题,包括完整的堆栈跟踪(赔率是好的,它已经试图告诉你问题是什么)。另外,请提供一个[mcve] ...因为您已经声明了文件复制代码的工作原理,在这种情况下,“minimal example”可能意味着“打印由'getText'返回的意外的'String'。 –
@ KevinJ.Chase我的问题已经由我自己回答了。我需要在这里发布我的答案吗? –