1

I have my application log file stored in the project directory. For better UI experience I want to put a button in my java application which says "Export Log files". I want to read from an existing file on a disk and allow it to be saved by user anywhere he wants so he won't have to go searching for the log files.

How is it possible to do it? I tried to Google but the result of these keyword searches doesn't show the links I would be interested in.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
rockstar
  • 3,512
  • 6
  • 40
  • 63
  • 1
    learn basics of Java first. Learn how to make a Swing UI with a button, learn how to display file dialog in Swing UI, learn how to read and write file. – Adrian Shum Sep 24 '14 at 01:50
  • 1
    Which part are you stuck on? [How to Use Buttons, Check Boxes, and Radio Buttons](http://docs.oracle.com/javase/tutorial/uiswing/components/button.html)? [How to Write an Action Listeners](http://docs.oracle.com/javase/tutorial/uiswing/events/actionlistener.html)? Or [Basic I/O](http://docs.oracle.com/javase/tutorial/essential/io/)? – MadProgrammer Sep 24 '14 at 01:51
  • @MadProgrammer i am stuck on the File I/O part . How to ``copy`` & ``paste`` file from one location to the new user specified location . Will i need to read file A and then write to file B or I can avoid read and writing . – rockstar Sep 24 '14 at 01:55
  • 1
    *"I tried to google but the result of these keyword searches"* Really? I suspect your searches were far too specific. Try instead searching 'x java tutorial' where `x` is a single word dealing with part of the task. – Andrew Thompson Sep 24 '14 at 01:55
  • 1
    @AndrewThompson Ok thanks I shall be more specific . I shall go through the File I/O parts . – rockstar Sep 24 '14 at 01:56
  • 2
    Amen, if you Google for "X then Y then Z", you'll never find it. Better Google for X, then for Y, then for Z, and then synthesize the whole from the parts using your intellect and efforts. – Hovercraft Full Of Eels Sep 24 '14 at 02:08

1 Answers1

3

Start by taking a look at Basic I/O. This will provide you with the basic concept of dealing with input/output streams and readers and writers.

You can also have a look at File I/O (Featuring NIO.2) which provides actually examples of copying files and directories...

Now, personally, I prefer to manually copy files using Input/OutputStreams or Reader/Writers. The reasons for this is I can provide progress indication of the copy process, which the NIO.2 API's don't provide...

For example, see JTextArea appending problems

Community
  • 1
  • 1
MadProgrammer
  • 343,457
  • 22
  • 230
  • 366