File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes JAVA FILE INPUT/OUTPUT Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "JAVA FILE INPUT/OUTPUT" Watch "JAVA FILE INPUT/OUTPUT" New topic
Author

JAVA FILE INPUT/OUTPUT

Philip Burgwin
Greenhorn

Joined: Mar 20, 2001
Posts: 3
Hi,
Could anybody please supply me (or let me know) the full .java source code to do the following:
Open up a simple text area window where the user is asked to type in there name. The user types there name in, clicks an 'ok' button and there name is then written to the file 'name.txt' on the local c:\.
Its for part of a coursework Im doing at college. I would be grateful if someone could let me know the code or even better email me the .java file(s). Im using Java Developement Kit Ver 1.1.8 (the 9mb one u get free from from javasoft).
Regards,
Phil,
HiOnMaiden@FreeNet.co.uk
Art Metzer
Ranch Hand

Joined: Oct 31, 2000
Posts: 241
Philip:
Please give us a little history. Which classes in the Java API are you planning on using? What have you attempted so far? What error message(s) did you get?
Art
Philip Burgwin
Greenhorn

Joined: Mar 20, 2001
Posts: 3
Well to be honest its my my first Java assignment. Ive got 2 months to do it but I know bugger all about Java @ moment.
The Java I/O is the main part of it really. If I can get Java file I/O working (just creating files on local hard drive/reading em back) then as I say the rest is just putting the I/O code into a Java user interface. I dont even have to send any files across net/intranet or anything - for the demo I need to give just on a standalone PC will do.
Im working thru the book 'core java 1.2 - Fundamentals' but nothing seems to work in chap12 (the one relavent for me!).
I figure everything needed is in the java.io class but Ive no idea were to begin and I cant find any SIMPLE java I/O examples similar to what I need on net anywhere.
Regards,
Phil.
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
I'm a little puzzled by your request. Presumably the aim of the coursework is that you do it yourself. Would you really learn as much by just copying one which someone else has written?
I'm sure we would all like to help you get the most from your course, but some things I reckon you have to at least try to do yourself. If this is not the case, please let us know. I'm sure many people here could knock up such a thing very quickly.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
OOps, you replied with more detail as I was composing that last one. You say that the examples are not working - what sort of errors are you getting? If we can get the examples working for you, then the rest should be easy. It may just be some small misunderstanding which is holding you up.
octavyn pittman
Ranch Hand

Joined: Mar 06, 2001
Posts: 134
Phil,
You can take a look at the I/O forum and look through the posts in the last year and find some simple examples I am sure. Writing to a file is very simple, and it would be a great experience for you to figure it out.
People here will be willing to work with you--even your most basic, seemingly idiotic questions. Everyone starts out somewhere. However, few people really want to rob you of a valuable learning experience, no matter how easy it would be for them to just give you some code.
Do you have a java environment set up? That is a good first step, if you haven't done it, but it sounds like you have. Once you are able to write and run the most basic java programs writing out to the screen through println() , you only have a few more steps to writing to a text file. And this won't be an applet in all likelihood, so concentrate on little Java apps in your tutorial/books. It really won't take too long for you to figure out how to do it--really understanding what's going on is what takes awhile.
OP
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
First you need to decide - are you going to do this as an applet (run from a browser so you need an HTML page), or as an application run from the command prompt (it matters). I am assuming that you are not yet to servlets etc.
Next you need to understand that there are going to be alot of examples using SWING GUIs. The version of java that you are using does not fully support swing even with a plug-in, so you will need to use the AWT for your GUI. (avoid all the JXXXXX classes).
Start out just getting an empty frame to come up.
Then add a TextField and Button to it.
Then add a Listener so your button hears when you are ready.
Last worry about IO.

[This message has been edited by Cindy Glass (edited April 05, 2001).]


"JavaRanch, where the deer and the Certified play" - David O'Meara
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
PS: all the versions are free. Are you allowed to use the 1.3 version? It's much better .

Get the Java 2 SDK SE (Standard Edition) from Sun at: http://www.sun.com/download/
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JAVA FILE INPUT/OUTPUT
 
Similar Threads
Reading parameter from JSP page
NT authentication using servlets..
Is this policy file correct?
copying file from client system to and storing in server
Reading .gif Images from a file