![Quote](https://www.javaprogrammingforums.com/images/misc/quote_icon.png)
Originally Posted by
Norm
It returns a String. The statement:
System.out.println(file.getAbsolutePath());
should print its value.
i see wht the problem i think.
i change to be before the url stuff, and now its print
try {
System.out.println(file.getAbsolutePath());
URL url = new URL(clientFolder);
URLConnection con = url.openConnection();
FilterOutputStream out = new FilterOutputStream(con.getOutputStream());
ImageIO.write(image, "jpg", out);
System.out.println("the image is uploaded successfully");
out.flush();
out.close();
} catch(Exception e) {
e.printStackTrace();
}
--- Update ---
maybe the URL not close and because url constructor its basically getting file its override the file not ?
--- Update ---
yes just i thinking
now its work, called after i call the function
FTPClient ftpClient = new FTPClient();
ftpClient.connect("dbachartechz.6te.net", 21);
ftpClient.login("dbachartechz.6te.net", "123321");
String clientFolder = "ftp://dbachartechz.6te.net:123321@dbachartechz.6te.net/ss/" + serial + "/" + imageName + ".jpg";
if(ftpClient.cwd("ss/" + serial + "/") == 250) {
ftpClient.changeWorkingDirectory("ss/" + serial + "/");
System.out.println("your folder is located");
ftpInsertImage(image, clientFolder, file);
} else if(ftpClient.cwd("ss/" + serial + "/") == 550) {
if(ftpClient.makeDirectory("ss/" + serial)) {
ftpClient.changeWorkingDirectory("ss/" + serial + "/");
System.out.println("the folder was created successfully");
ftpInsertImage(image, clientFolder, file);
}
}
if(new File(file.getAbsolutePath()).delete()) System.out.println("file deleted");
} catch(Exception e) {
e.printStackTrace();
}
}
public static void ftpInsertImage(BufferedImage image, String clientFolder, File file) {
try {
URL url = new URL(clientFolder);
URLConnection con = url.openConnection();
FilterOutputStream out = new FilterOutputStream(con.getOutputStream());
ImageIO.write(image, "jpg", out);
System.out.println("the image is uploaded successfully");
out.flush();
out.close();
} catch(Exception e) {
e.printStackTrace();
}
}