|
| |||||||||
| Tags: file, java, programming, save |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| 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
| ||||
| ||||
| 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
| |||
| |||
| 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
| ||||
| ||||
| 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
| ||||
| ||||
| 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
| ||||
| ||||
| 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"); Code: try
{
ImageIO.write(buffer, "GIF", new File("picture.gif"));
}
catch (IOException e)
{
e.printStackTrace();
} |
![]() |
|
| Thread Tools | Search this Thread |
| |
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 |