返回信息流public synchronized void upload() {
。。。。。。
String message = new String(file.getName());
String title = new String("文件已经存在");
//弹出对话框
int messageType = JOptionPane.QUESTION_MESSAGE;
int choose = JOptionPane.showConfirmDialog(this, message,title, JOptionPane.YES_NO_OPTION,messageType);
。。。。。。
}
此时对话框无法弹出,请问是否与方法设成了synchronized有关系,怎么解决?
这是一条镜像帖。来源:北邮人论坛 / java / #12526同步于 2009/12/2
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Java机器人发帖
Swing弹出对话框的问题
ILoveColaCao
2009/12/2镜像同步4 回复
订阅后,新回复会通过你的通知中心匿名送达。
4 条回复
public boolean upload(File file) throws IOException {
InputStream in = null;
boolean flag = false; //上传是否成功
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
ftpClient.setFileTransferMode(FTP.STREAM_TRANSFER_MODE);
try {
if (file.isFile()) {
try{
in = new FileInputStream(file.getAbsolutePath());
//Stores a file on the server using the given name and taking input from the given InputStream
flag = ftpClient.storeFile(toISO(file.getName()), in);
}catch(Exception e){
//ClientLogHandler.getInstance().error("FTP模块", this.getClass(), e);
}finally{
in.close();
}
} else {
String remote = ftpClient.printWorkingDirectory(); //获得远程当前目录
String newRemote = null; //新建目录
String sRemote = ""; //调试用
try{
if(!remote.equals("/")){ //远程当前目录为根目录
newRemote = remote + "/"+ toISO(file.getName());
sRemote = remote + "/"+ file.getName();
}else{
newRemote = remote + toISO(file.getName());
sRemote = remote + file.getName();
}
}catch(Exception e){
//ClientLogHandler.getInstance().error("FTP模块", this.getClass(), e);
}
if(newRemote!=null){
// Creates a new subdirectory on the FTP server
ftpClient.makeDirectory(newRemote);
File[] list = file.listFiles(); //获得子目录和文件
if(list.length==0){
flag = true;
}else{
// Change the current working directory of the FTP session.
//将服务器端的目录转变到新建的子目录下
boolean changeDir = ftpClient.changeWorkingDirectory(newRemote);
if (changeDir) {
for (int i = 0; i < list.length; i++) {
if(list[i].isFile()){
in = new FileInputStream(list[i].getAbsolutePath());
try{
flag = ftpClient.storeFile(toISO(list[i].getName()), in);
}catch(Exception e){
//ClientLogHandler.getInstance().error("FTP模块", this.getClass(), e);
}finally{
in.close();
}
}else{
upload(list[i]); //递归调用上传文件的方法
}
}
//Change to the parent directory of the current working directory
ftpClient.changeToParentDirectory();
}
}
}
}
// if (flag) {
TxtArea.append("响应:"+file.getName() + " 上传成功 ^_^\n");
String directory = ftpClient.printWorkingDirectory();
if(directory!=null)
getSubFiles(directory);
return true;
// }else{
// TxtArea.append("响应:"+file.getName() + " 上传失败 @_@\n");
// }
} catch (FileNotFoundException e) {
//ClientLogHandler.getInstance().error("FTP模块", this.getClass(), e);
TxtArea.append("响应:"+e.getMessage()+"\n");
} catch(IOException e){
//ClientLogHandler.getInstance().error("FTP模块", this.getClass(), e);
TxtArea.append("响应:"+e.getMessage()+"\n");
} finally {
try{
if (in != null) {
in.close();
}
}catch(Exception e){
//ClientLogHandler.getInstance().error("FTP模块", this.getClass(), e);
}
}
return flag;
}