*
The moose likes Beginning Java and the fly likes java program to create a file from user inputs. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "java program to create a file from user inputs." Watch "java program to create a file from user inputs." New topic
Author

java program to create a file from user inputs.

Ramakanta Sahoo
Ranch Hand

Joined: Aug 23, 2008
Posts: 254

Hi All,

I'm very new to java.so dont know much about it.
i'm trying to get a input from user and write it into a file named alpe.jacl
My question is how I will be able to get multiple userinputs like address and jobtitle etc etc in the same single window.
and the code will save the inputs in alpe.txt one by one in a new line like
nameis name
address russia
jobtitle dev



Thanks a lot.


Regards, Ricky
Oracle Weblogic 10g Certified Expert TechPaste.Com
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38016
    
  22
Suggest you see whether there is a writeLine() method rather than write; that will mean you can forget the "\r\n" which only really applies to Windows. Try here.
You might want System.out.println("Your file has been written."); instead.

You can repeat the JOptionPane calls for the other attributes; your writing calls look quite good otherwise.
Ramakanta Sahoo
Ranch Hand

Joined: Aug 23, 2008
Posts: 254

Thanks,as i told before am very new to java, so still I'm not able to get it correctly.
could anyone please explain with an example. or take my program as an example and modify to show it up.
one more thing i tried the same file to compile and run in unix but it compiled but it failed to run.

Thanks
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

one more thing i tried the same file to compile and run in unix but it compiled but it failed to run.


What was the error? Do you have the required privileges?

And there is no need of recompilation unless you are using native code.
That's Java


SCJP, SCWCD.
|Asking Good Questions|
Ramakanta Sahoo
Ranch Hand

Joined: Aug 23, 2008
Posts: 254

Correct.I was getting below error

Its because of file permission.
i configured java for root only thats why its not allowing normal users to run it.
This problem solved But what about the examples...
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38016
    
  22
Did the file class compile correctly? Are you in the correct folder to find it? The commonest reason for that Exception is that your .class file isn't where you are.
Ramakanta Sahoo
Ranch Hand

Joined: Aug 23, 2008
Posts: 254

No,
It's compiling correctly.
and also I dont have any problem run the class file now once i switched to root user.
I was asking about my first question...
please explain with example hoe i will be able to get multiple user inputs from a single window and write it to a file..

Thanks,
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

You need to do a Swing application as the input form, and when you submit it you will then read from the forms input fields, and write them to the file.
Originally posted by Ricky Rosan:
I was asking about my first question...
please explain with example hoe i will be able to get multiple user inputs from a single window and write it to a file..


Regards, Rene Larsen
Dropbox Invite
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18529
    
  40

I was asking about my first question...
please explain with example hoe i will be able to get multiple user inputs from a single window and write it to a file..


Unfortunately, this is not really a specific question -- it is asking for an example that does your homework problem.

You need to get specific. What is the next step to get you application closer to the assignment? And are you running into any particular issues? Now...

If you don't know what your next steps should be, I suggest you take a look at some of the methods of the FileWriter class -- which you are using. You need to get confortable with writing to the file. Don't worry about get the data to write yet.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Ramakanta Sahoo
Ranch Hand

Joined: Aug 23, 2008
Posts: 254

Hi all,

For multiple user inputs I did like


But this giving me new windows each time i enter a input.
I want this all inputs from a single window.
what should i do to give all inputs from a single window.
Do I need to create a window frame.. If yes then from where should i start..
Give some suggestions.

Thanks.
Ricky
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19653
    
  18

JOptionPane.showConfirmDialog can do it for you, but you need to create and read the text fields yourself:

The trick is, for most of the showXXXDialog methods of JOptionPane, the message can be an array. If this is the case, the elements are positioned vertically, with labels being turned into JLabels.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Ramakanta Sahoo
Ranch Hand

Joined: Aug 23, 2008
Posts: 254

Hi Rob,
Thanks.
I tried your suggestion. Now its showing all in a single window but i ran into a new problem. It suppose to create a file called alpe.jacl where all values entered will be stored.
So I did like this:

Now one more problem I'm not able to figure out how i will be able to execute ./install.sh script at command line present at the same folder with clicking on a button named Install.

How should i go further do i need to create a button named INSTALL and assign a task ./install.sh on click event.
Am not sure help me.

Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java program to create a file from user inputs.
 
Similar Threads
Populating A Folder With Files - Access Denied
writing unicode to a file
write to f file
HTTP get Request
problem opening a new word file