471,896 Members | 1,883 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,896 software developers and data experts.

File Writing.. Overwriting

Hi
what do i have to use in order to browse for a jpeg.file and save it to a specific directory... and overwrite the existing

and does it only work for jpeg? or any kind of file



thanks in advance..
Feb 1 '08 #1
7 12829
r035198x
13,262 8TB
Hi
what do i have to use in order to browse for a jpeg.file and save it to a specific directory... and overwrite the existing

and does it only work for jpeg? or any kind of file



thanks in advance..
Use a JFileChooser to browse to the file.
Use the File.renameTo method for the moving. Note for the overwriting to work with this one, you'll probably need to delete the old file first. (Read about it in the docs)
It's not limited to jpeg files only.
Feb 1 '08 #2
import java.awt.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
import java.awt.event.*;

public class FileOverWrite {

public static void main(String[] args) throws Exception {

String outFileName = "jpg";
String fileName=args[1];
Image image;

Toolkit toolkit = Toolkit.getDefaultToolkit();
image = toolkit.getImage(fileName);
ImageIO.write(image, "jpg", new File(outFileName));

}
}

so far this is what i have made...

the error it gives is:
cannot find symbol method write(java.awt.Image,java.lang.String,java.io.File )

whats wrong with the code.. i found the .write in the api
Feb 1 '08 #3
r035198x
13,262 8TB
import java.awt.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
import java.awt.event.*;

public class FileOverWrite {

public static void main(String[] args) throws Exception {

String outFileName = "jpg";
String fileName=args[1];
Image image;

Toolkit toolkit = Toolkit.getDefaultToolkit();
image = toolkit.getImage(fileName);
ImageIO.write(image, "jpg", new File(outFileName));

}
}

so far this is what i have made...

the error it gives is:
cannot find symbol method write(java.awt.Image,java.lang.String,java.io.File )

whats wrong with the code.. i found the .write in the api

Did you see my reply above?
Feb 1 '08 #4
ohh im sorry ill try that one ... just a little tired i guess ... :D


is there a sample code i could refer to in using this?
Feb 1 '08 #5
r035198x
13,262 8TB
ohh im sorry ill try that one ... just a little tired i guess ... :D


is there a sample code i could refer to in using this?
Perhaps if you were to actually open those links ...
Feb 1 '08 #6
public class FileOverWrite {

public static void main(String[] args) throws Exception {

String fileName=args[0];
File fp = new File(fileName);
String writeFolder="C:\\pic2";
fp.renameTo(new File(writeFolder));

}
}
no file is being created but it gives no errors : this is my input C:\java FileOverWrite c:\pic\image.jpg


c:\pic\image.jpg is the file i want to copy
i want to put it in c:\ what should i add to the code?
Feb 1 '08 #7
r035198x
13,262 8TB
public class FileOverWrite {

public static void main(String[] args) throws Exception {

String fileName=args[0];
File fp = new File(fileName);
String writeFolder="C:\\pic2";
fp.renameTo(new File(writeFolder));

}
}
no file is being created but it gives no errors : this is my input C:\java FileOverWrite c:\pic\image.jpg


c:\pic\image.jpg is the file i want to copy
i want to put it in c:\ what should i add to the code?
1.) Use code tags when posting code
2.)
The rename operation might not be able to move a file from one filesystem to another, it might not be atomic, and it might not succeed if a file with the destination abstract pathname already exists. The return value should always be checked to make sure that the rename operation was successful.
From the API docs (the link I posted above)
Feb 1 '08 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

16 posts views Thread by nephish | last post: by
4 posts views Thread by Oliver Knoll | last post: by
4 posts views Thread by phantom | last post: by
3 posts views Thread by localpricemaps | last post: by
3 posts views Thread by DHarry | last post: by
6 posts views Thread by tomtown.net | last post: by
8 posts views Thread by hiro | last post: by
13 posts views Thread by rohit | last post: by
12 posts views Thread by glennanthonyb | last post: by
reply views Thread by YellowAndGreen | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.