• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java program to create a file from user inputs.

 
Ramakanta Sahoo
Ranch Hand
Posts: 255
Fedora Firefox Browser Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Sheriff
Posts: 48382
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 255
Fedora Firefox Browser Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ramakanta Sahoo
Ranch Hand
Posts: 255
Fedora Firefox Browser Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48382
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 255
Fedora Firefox Browser Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
Henry Wong
author
Marshal
Pie
Posts: 20882
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ramakanta Sahoo
Ranch Hand
Posts: 255
Fedora Firefox Browser Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20494
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ramakanta Sahoo
Ranch Hand
Posts: 255
Fedora Firefox Browser Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic