Results 1 to 10 of 10
- 09-18-2008, 09:21 PM #1
Member
- Join Date
- Sep 2008
- Posts
- 16
- Rep Power
- 0
how to use JFileChooser to select file -> string
I'm trying to use jfilechooser to select a text file, and convert it to a string that i can manipulate. The file is going to be fairly large so i don't know if i need a buffer or anything.
My end goal is to select a text file, format it by replacing certain strings, and then output the newly formatted text file.
Thanks in advance
- 09-18-2008, 09:59 PM #2
You forgot to post your code and explain what your problem is.
- 09-18-2008, 10:07 PM #3
Member
- Join Date
- Sep 2008
- Posts
- 16
- Rep Power
- 0
im' pretty new to java. My problem is i hve a JForm and the user selects the file. I stored the file as a file object...
Java Code:private void FileChooserActionPerformed(java.awt.event.ActionEvent evt) { int retval = FileChooser.showOpenDialog(null); if (retval == FileChooser.APPROVE_OPTION) { File input = FileChooser.getSelectedFile(); toFormat = input.String(); }
- 09-18-2008, 10:14 PM #4
Senior Member
- Join Date
- Aug 2008
- Posts
- 384
- Rep Power
- 12
String s = String.valueOf(File);
might work.I die a little on the inside...
Every time I get shot.
- 09-18-2008, 10:17 PM #5
Member
- Join Date
- Sep 2008
- Posts
- 16
- Rep Power
- 0
the file i'm trying to select is very large, ~160 megs. It's technically a csv file. not sure if this will cause any problems as i have to parse through the entire file to replace about 7 strings with different strings..
- 09-18-2008, 10:19 PM #6don't knwo how to manipulate/work with a File object
I want to convert the file to a string
or do you want to work on the name of the file?
- 09-18-2008, 10:21 PM #7
Senior Member
- Join Date
- Aug 2008
- Posts
- 384
- Rep Power
- 12
BufferedReader file = new BufferedReader(new FileReader(String));
String s = file.readLine();
and to write use
BufferedWriter file = new BufferedWriter(new FileWriter(String));
don't forget to use file.flush & file.close for both.
Instead of String you also can use a file, I think.
This is what you ment?I die a little on the inside...
Every time I get shot.
- 09-18-2008, 10:33 PM #8
Member
- Join Date
- Sep 2008
- Posts
- 16
- Rep Power
- 0
i went over the doc but was confused about it...
I'm trying to read the contents of the file(.csv file) and convert it to a string so i can use regular expressions to find/replace certain text in the line, then save the newly formatted file to a .txt
- 09-18-2008, 10:44 PM #9
Senior Member
- Join Date
- Aug 2008
- Posts
- 384
- Rep Power
- 12
That's gonna be one hell of a string. Use a loop to compare it all line by line.
I die a little on the inside...
Every time I get shot.
- 09-18-2008, 10:45 PM #10
Similar Threads
-
[SOLVED] jfilechooser for saving a file....?
By prabhurangan in forum AWT / SwingReplies: 10Last Post: 10-06-2013, 11:17 PM -
how to use JFileChooser to select file -> string
By gezzel in forum AWT / SwingReplies: 15Last Post: 10-23-2008, 06:34 AM -
Cannot display a random string from .dat file
By explosion242 in forum New To JavaReplies: 2Last Post: 09-18-2008, 02:48 PM -
can i update the tag value of XMl file by other value(string
By pankaj_salwan in forum Advanced JavaReplies: 7Last Post: 07-04-2008, 09:12 AM -
Read a string from a txt file
By cachi in forum Java AppletsReplies: 1Last Post: 08-07-2007, 08:50 AM
Bookmarks