• Post Reply Bookmark Topic Watch Topic
  • New Topic

Textfield to file  RSS feed

 
Karl Wase
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First Im not really sure what to call the thread and if this is the right place to put it but let's hope it works out for now.
--------------------------------------------------------------------------------------------------------------------------------------
Hello and Thanks for all help before hand

I'm working on a Java project with some friends if mine and was looking for some help.

We need a textfield which, what you write inside of it should be saved do a textdocument (something basic like .txt). It's only supposed to support a file path and not a whole bunch of text.

[C:\User\ ] //textfield
In this case, "C:\User\" or whatever you write inside of the textfield, should be saved to an textfile.

So I was hoping that someone could show an example of this.

Thanks once again for all your comments and help

 
Olivier Legat
Ranch Hand
Posts: 176
Chrome Mac Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Karl

Karl Wase wrote:
We need a textfield which, what you write inside of it should be saved do a textdocument (something basic like .txt). It's only supposed to support a file path and not a whole bunch of text.


So what exactly do you mean by this? Does the TextField hold the filepath or the content of the file? If it holds the content of the file then where are you planning to set filepath. In the arguments of the main?

You can use the method TextField.getText() (which returns a String) to obtain the content of the field and then use the RandomAccessFile class to write it to a file.

Assuming that the TextField holds the content and the Argument 0 of the main method holds the filepath you do something like this:



Use my code if you want, free of charge . Just create a Frame with a TextField and Button (or something like that) and create an instance of this class using the constructor. Then in the ActionListener class (or whatever you're using for the Button) call the method ToFile.writeToFile().
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, Olivier.

And welcome to JavaRanch ( ), Karl
 
Olivier Legat
Ranch Hand
Posts: 176
Chrome Mac Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pleasure is all mine
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!