Results 1 to 2 of 2
  1. #1
    juan4412 is offline Member
    Join Date
    Jun 2013
    Posts
    13
    Rep Power
    0

    Default Output Array To Text File

    I am outputting my array to a File - but how can I specify that I want it to export to a .txt extension?
    Java Code:
        public void WriteArraysToText()
        {
            BufferedWriter writer = null;
            try {
                String timeLog = new SimpleDateFormat("yyyyMMdd_HHmmss").format(Calendar.getInstance().getTime());
                File logFile = new File(timeLog);
                writer = new BufferedWriter(new FileWriter(logFile));
                for (String temp : filepaths) {
                    writer.write(temp);
                    writer.newLine();
                }
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                try {
                    writer.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }

  2. #2
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,966
    Rep Power
    7

    Default Re: Output Array To Text File

    Why not add ".txt" to the filename?
    Java Code:
    File logFile = new File(timeLog + ".txt");
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

Similar Threads

  1. Input/output to a text file through a GUI
    By turtles in forum New To Java
    Replies: 19
    Last Post: 12-24-2013, 08:22 PM
  2. Writing a block of text as it is to output file
    By bikashg in forum New To Java
    Replies: 5
    Last Post: 05-29-2010, 11:38 PM
  3. Output to a text file
    By sfe23 in forum New To Java
    Replies: 4
    Last Post: 03-26-2009, 10:44 PM
  4. Replies: 3
    Last Post: 02-16-2009, 09:20 PM
  5. Simply output the result to a text file.
    By silvia in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 05:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •