473,412 Members | 1,921 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 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 13037
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

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

Similar topics

8
by: Stewart | last post by:
is there any way this can be done? I've looked at the help files and checked out as many tutorials as i could find on the net (as always) but no joy. thanks
16
by: nephish | last post by:
Hey there, kinda newbie question here. i know how to read the lines of a txt file. i know how to write a txt file. but how do i overwrite a line value with another value ? i mean, how do go...
4
by: Oliver Knoll | last post by:
According to my ANSI book, tmpfile() creates a file with wb+ mode (that is just writing, right?). How would one reopen it for reading? I got the following (which works): FILE *tmpFile =...
4
by: phantom | last post by:
Hi All. I am having a problem writing to a file. I can successfully open the file and write the contents using fprintf, however if the writing is not done for a while in the process the file...
3
by: localpricemaps | last post by:
i am having a problem writing a tuple to a text file. my code is below. what i end up getting is a text file that looks like this burger, 7up burger, 7up burger, 7up and this is instead...
3
by: DHarry | last post by:
How can I clear a text file without deleting and creating a new (empty) file?
6
by: tomtown.net | last post by:
Hello I'm trying to get a single line removed from a text file using a search pattern (pretty simple: if line contains "NODE1") -> remove line). To achieve this I's like to operate with only the...
8
by: hiro | last post by:
Hi there, I'm very new to python, the problem I need to solve is whats the "best/ simplest/cleanest" way to read in multiple files (ascii), do stuff to them, and write them out(ascii). --...
13
by: rohit | last post by:
Hi All, I am new to C language.I want to read integers from a text file and want to do some operation in the main program.To be more specific I need to multiply each of these integers with another...
12
by: glennanthonyb | last post by:
Hi The company I work for has finally woken up to data security on our field laptops. I'm writing something in C# that will allow remote deletion of sensitive data and I don't believe...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.