473,699 Members | 2,532 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

File Writing.. Overwriting

42 New Member
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 13060
r035198x
13,262 MVP
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
akoymakoy
42 New Member
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.getDefa ultToolkit();
image = toolkit.getImag e(fileName);
ImageIO.write(i mage, "jpg", new File(outFileNam e));

}
}

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 MVP
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.getDefa ultToolkit();
image = toolkit.getImag e(fileName);
ImageIO.write(i mage, "jpg", new File(outFileNam e));

}
}

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
akoymakoy
42 New Member
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 MVP
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
akoymakoy
42 New Member
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(writeFolde r));

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


c:\pic\image.jp g 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 MVP
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(writeFolde r));

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


c:\pic\image.jp g 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
3293
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
3026
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 to, say, line 3 of a text file and replace what is written on line 3 with something else?
4
9836
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 = tmpfile(); /* write into tmpFile */ ...
4
1510
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 write returns a status -1. To elaborate here is the code segment main (... , ...) {
3
2746
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 of getting a list that should look like this
3
15804
by: DHarry | last post by:
How can I clear a text file without deleting and creating a new (empty) file?
6
41958
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 original file and no temp file since the file is 1. on a network resource 2. pretty big 3. accessed by plenty of clients. Copying the file or reading everything into an array and then writing it back using the StreamWriter would lock the file...
8
1580
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). -- import os filePath = ('O:/spam/eggs/')
13
10414
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 set of integers stored in an array.It would be a great help if you could provide some code for it.I tried the function fscanf but by that I am able to read only the first integer of the text file.Please help me.
12
4725
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 File.Delete() will be sufficient. Is there anything in .NET that removes any remanence of the file? If it isn't going to be easy, does anyone know of a component that I can hook into to do the dirty work, free of otherwise?
0
9199
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9054
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8943
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7785
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5884
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4391
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3075
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2016
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.