Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , ,

Sponsored Links



Unable to Save A File In Java

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 08-03-2010
Member
 
Join Date: Nov 2009
Posts: 124
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.
Reply With Quote
  #2  
Old 08-03-2010
Praetor's Avatar
Member
 
Join Date: Apr 2008
Posts: 1,937
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();
}
Reply With Quote
  #3  
Old 08-03-2010
Member
 
Join Date: May 2008
Posts: 1,990
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.
Reply With Quote
  #4  
Old 08-03-2010
kelfro's Avatar
Member
 
Join Date: Apr 2008
Posts: 1,976
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");
Reply With Quote
  #5  
Old 08-03-2010
Reegan's Avatar
Member
 
Join Date: Oct 2005
Posts: 2,299
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)" ;
}
}
Reply With Quote
  #6  
Old 08-03-2010
Zecho's Avatar
Member
 
Join Date: May 2008
Posts: 2,267
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();
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Unable to Save A File In Java"
Thread Thread Starter Forum Replies Last Post
Unable to save PDF file on Safari 5.1.2 Here-There Technology & Internet 6 4 Weeks Ago 11:02 PM
unable to save resume file in Torrent TechPredator Technology & Internet 8 14-09-2011 12:41 AM
Unable to save file in Notepad++ Cade Windows Software 5 17-02-2010 03:33 AM
Unable to save the file, file is too large Suzane Technology & Internet 2 29-05-2009 12:16 AM
Unable to save file (Error 1120) StephanieRice Software Development 3 08-05-2009 07:38 PM


All times are GMT +5.5. The time now is 12:10 PM.