Results 1 to 10 of 10
- 02-04-2009, 06:57 AM #1
Member
- Join Date
- Jan 2009
- Posts
- 31
- Rep Power
- 0
Read and Open *.txt Files? help!!
hi guys! I have been searching through the forum but haven't found the simplest explanation on how to open a file so the user can see how the texts were saved.
can anyone please, kindly help me? any ideas?
Java Code:Example: Step 1: I created a file named "SavedHere.txt"; Step 2: The user then writes anything, for example, a paragraph, with indents and all that stuff. Step 3: [COLOR="DarkRed"]here's my problem.[/COLOR] [COLOR="Black"]the user then clicks a button labeled "view file"[/COLOR]. **I just want to know how to open a file for the user to see his input** Thanks a lot in advance!:)
- 02-04-2009, 07:10 AM #2
Senior Member
- Join Date
- Dec 2008
- Location
- Hong Kong
- Posts
- 473
- Rep Power
- 5
can try
BufferedReader in = new BufferedReader(new FileReader(File));
in.readline() or other read methods
- 02-04-2009, 07:24 AM #3
Member
- Join Date
- Jan 2009
- Posts
- 31
- Rep Power
- 0
thanks! that worked!†
- 02-04-2009, 09:55 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Do you want to read the text file or just open it?
- 02-05-2009, 03:02 AM #5
Member
- Join Date
- Jan 2009
- Posts
- 31
- Rep Power
- 0
Hi Eranga.. I just want to open the file.. like popping up somewhere..
- 02-05-2009, 03:05 AM #6
Senior Member
- Join Date
- Dec 2008
- Posts
- 526
- Rep Power
- 0
to open with you app you can use JFileChooser to get an absolute path and then read the file and place its test to a JTextArea
- 02-05-2009, 03:58 AM #7
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 10-30-2009, 11:21 PM #8
Member
- Join Date
- Oct 2009
- Posts
- 13
- Rep Power
- 0
If i want the user to click in a button and then to open a specific file how i can do it? I don't want to do it with file chooser beause the file is specific..
:)
- 11-01-2009, 03:41 PM #9
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Yes you can do that. Did you read about the Process class? It's what all you want.
Say you've a text file name test.txt on C:\ drive. What happen if you type the complete path on Run command (on windows)? OS identified the relevant application and pass the variable to it. Same thing you can do in Process class.
Just go through the following code segment.
Java Code:public static void main(String[] args) { String fileName = "c:\\test.txt"; String[] commands = {"cmd", "/c", fileName}; Runtime.getRuntime().exec(commands); }
- 11-01-2009, 03:42 PM #10
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
First read about the Process class from the Java Doc, then look at the code segment. You can have a better idea then.
Similar Threads
-
Open xls file in read-write mode
By rdhaware in forum Advanced JavaReplies: 1Last Post: 02-03-2009, 08:12 AM -
Data files - how to read random line?
By Exhonour in forum New To JavaReplies: 4Last Post: 01-20-2009, 08:28 PM -
Saved files are coming back as read-only
By Manoeuvre in forum EclipseReplies: 0Last Post: 11-21-2008, 05:18 PM -
[SOLVED] Read/write files using applets
By coolFrenzi in forum Advanced JavaReplies: 3Last Post: 11-17-2008, 10:45 PM -
java.io.IOException: Unable to read entire block; 493 bytes read before EOF; expected
By kushagra in forum New To JavaReplies: 5Last Post: 10-17-2008, 02:13 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks