Results 1 to 6 of 6

Thread: Unable to Save A File In Java

  1. #1
    Join Date
    Nov 2009
    Posts
    140

    Unable to Save A File In Java

    Hello, I am working on java programming working on it. But, while working on it, I am getting the problem of the saving file whether it is the file of any extension or of any image file in java. I have created one file and want to save that file into the directory of my application. But, I am not able to save that file. So, if you are having any knowledge about it, then please help me to get the solution.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Unable to Save A File In Java

    If you are not able to save a file in your storage device with the help of java then simply use the code below:
    Code:
    try 
    {
    ImageIO.write(buffer, "GIF", new File("image.gif"));
    }
    catch (IOException ie) 
    {
    ie.printStackTrace();
    }

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: Unable to Save A File In Java

    For getting the solution for this program you just need to simply make use of the Filechooser from java. File choosers provide a GUI for navigating the file system, and then either choosing a file or directory from a list, or entering the name of a file or directory. To display a file chooser, you usually use the JFileChooser API to show a modal dialog containing the file chooser. Another way to present a file chooser is to add an instance of JFileChooser to a container.

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Unable to Save A File In Java

    This is quiet simple to achieve the saving of the file with the help java. But for that is necessary to get the path which is related to the relative path. For that you can simply make use of the source code below:
    Code:
    String relatedpath = request.getSession().getServletContext().getRealPath("/ picture1.gif");

  5. #5
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Unable to Save A File In Java

    Hi, I have the code below which if you use then you will able to show the files which are having .java extension. So, it will definitely help you.
    Code:
    import javax.swing.*;
    import java.io.*;
    public class JavaFileChoser extends javax.swing.filechooser.FileFilter
    {
    public boolean receive (File file) {
    return file.getName ().toLowerCase ().endsWith (".java")|| file.isDirectory ();
    }
    public String getDescription () {
    return "Java files (*.java)" ;
    }
    }

  6. #6
    Join Date
    May 2008
    Posts
    2,297

    Re: Unable to Save A File In Java

    Hello, first make use of the code below for getting the relative path of the file:
    Code:
    String relativepath = ((HttpServletRequest) request). getSession (). getServletContext (). getRealPath ("picture1.gif");
    Then simply use the code below:
    Code:
    try 
    {
    ImageIO.write(buffer, "GIF", new File("picture.gif"));
    }
    catch (IOException e) 
    {
    e.printStackTrace();
    }

Similar Threads

  1. Unable to save PDF file on Safari 5.1.2
    By Here-There in forum Technology & Internet
    Replies: 7
    Last Post: 04-05-2012, 03:35 PM
  2. Unable to save file in Creative WaveStudio 7
    By Quasim in forum Windows Software
    Replies: 3
    Last Post: 18-07-2011, 06:09 PM
  3. Unable to save file in Notepad++
    By Cade in forum Windows Software
    Replies: 5
    Last Post: 17-02-2010, 03:33 AM
  4. Unable to save the file, file is too large
    By Suzane in forum Technology & Internet
    Replies: 2
    Last Post: 28-05-2009, 11:16 PM
  5. Unable to save file (Error 1120)
    By StephanieRice in forum Software Development
    Replies: 3
    Last Post: 08-05-2009, 06:38 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,527,791.87227 seconds with 16 queries