Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: IOException while accesing files

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default IOException while accesing files

    Hi iam trying to read a file and write the contents into another file present in other directory.Iam using the following method
     public static void storeFile(String fileName, String fileContents){
     
            BufferedWriter writer = null;
            if (log.isDebugEnabled())log.debug("File name to store" + fileName);
    		System.out.println("This is from FileOperations----storeFile()-----filename to store "+fileName);
     
            try {
     
                FileWriter fileWriter = new FileWriter(fileName);
    	    writer = new BufferedWriter(fileWriter);
    			System.out.println(writer);
                writer.write(fileContents, 0, fileContents.length());
    			System.out.println("This is from File operations-----------------------4");
            }
            catch (IOException ex) {
    			System.out.println("This is from IOEXception===========");
                ex.printStackTrace();
            }
            finally {
                try {
                    writer.close();
                }
                catch (IOException ex) {
    				System.out.println("This is from finally ------");
                    ex.printStackTrace();
                }
     
            }
        }

    iam getting the following output

    This is from FileOperations----storeFile()-----filename to store D:/Australia/T
    VETL/Transform/Transform/trunk/ETLFileStore/ETLOutputs/Output \CAPVOLMARKETDATA
    HISTORICAL-11292011_11267.xml
    This is from File operations-----------------------1
    This is from File operations-----------------------2
    This is from IOEXception===========

    can anyone help me to solve this .....................?
    Last edited by JavaPF; November 29th, 2011 at 06:33 AM. Reason: Use highlight tags and post in the correct forum!


  2. #2
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: IOException while accesing files

    And how do you need the help? What is the problem with your above code and what do you expect it to do? We can't read minds though.

  3. #3
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: IOException while accesing files

    We are probably going to have to see all of your code. Can you also post the full StackTrace.
    Are you sure the path to your file is correct?
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

Similar Threads

  1. java.io.IOException: Premature EOF
    By CrazyVag in forum File I/O & Other I/O Streams
    Replies: 8
    Last Post: December 19th, 2012, 08:32 AM
  2. Replies: 5
    Last Post: November 16th, 2011, 11:22 AM
  3. Replies: 1
    Last Post: March 22nd, 2011, 06:59 PM
  4. Help with toString and accesing user input
    By waltersk20 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 1st, 2010, 07:58 PM
  5. Help needed for "java.io.IOException: Not in GZIP format"
    By goldest in forum File I/O & Other I/O Streams
    Replies: 5
    Last Post: August 10th, 2010, 03:05 AM