-
How to add a feature to save a file in GUI
I have created the file menu. In that I have saveAs Icon. Once the user clicks
on that Icon, how to save the file?
-
Re: How to add a feature to save a file in GUI
Depends on what you are trying to save.
What you are interested in is streams and buffers. Check out the documentation
for the java.io package on Suns website. The following may get you started.
It simply opens a file and writes a line of data followed by a blank line.
Then closes the file.
import java.io.BufferedWriter;
import java.io.FileWriter;
public class Test {
private void makeData(String fileName) {
// Open the datafile.
FileWriter outFile = new FileWriter(fileName);
BufferedWriter buff = new BufferedWriter(outFile);
// Write out some data.
buff.write("This is some data");
buff.newLine();
// Close the file.
buff.close();
outFile.close();
}
public static void main(String[] args) {
makeData("rob.txt");
}
}
"Mallu" <java.@127.0.0.1> wrote:
>
>I have created the file menu. In that I have saveAs Icon. Once the user
clicks
>on that Icon, how to save the file?
-
Re: How to add a feature to save a file in GUI
Or were you wanting to know how to setup the event in order to save the file?
If what I have provided is not enough, please provide more info.
Thanks
"Rob Abbe" <rabbe@mn.rr.com> wrote:
>
>Depends on what you are trying to save.
>
>What you are interested in is streams and buffers. Check out the documentation
>for the java.io package on Suns website. The following may get you started.
> It simply opens a file and writes a line of data followed by a blank line.
> Then closes the file.
>
>import java.io.BufferedWriter;
>import java.io.FileWriter;
>
>public class Test {
> private void makeData(String fileName) {
> // Open the datafile.
> FileWriter outFile = new FileWriter(fileName);
> BufferedWriter buff = new BufferedWriter(outFile);
>
> // Write out some data.
> buff.write("This is some data");
> buff.newLine();
>
> // Close the file.
> buff.close();
> outFile.close();
> }
>
> public static void main(String[] args) {
> makeData("rob.txt");
> }
>}
>
>
>"Mallu" <java.@127.0.0.1> wrote:
>>
>>I have created the file menu. In that I have saveAs Icon. Once the user
>clicks
>>on that Icon, how to save the file?
>
-
Re: How to add a feature to save a file in GUI
"Mallu" <java.@127.0.0.1> wrote:
>
>I have created the file menu. In that I have saveAs Icon. Once the user
clicks
>on that Icon, how to save the file?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks