I have a problem with the JFileChooser class. I am using the following class (that I did write) to load several files one after the other, and it usually works for 2 or 3 files (sometimes 1, sometimes 6, looks random even though it must not be) and at a point, it freezes at showOpenDialog(null), no exception is thrown, nothing returned either.
I really don't know where it's coming from.
Here's my class:
public class CustomFileChooser extends JFileChooser {
public File chooseFile(String windowTitle, String description, String extension, boolean mustExist) {
setDialogTitle(windowTitle);
resetChoosableFileFilters();
setAcceptAllFileFilterUsed(false);
addChoosableFileFilter(new CustomFileFilter(description, new String[] {extension}));
setSelectedFile(new File(""));
if (mustExist) {
setApproveButtonText("Open");
} else {
setApproveButtonText("Save");
}
File file = null;
while (file == null) {
if (showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
file = getSelectedFile();
if (mustExist) {
if (!file.canRead()) {
file = null;
JOptionPane.showMessageDialog(null, "Cannot read from the specified file!", "Error while opening the file", JOptionPane.ERROR_MESSAGE);
}
} else {
if (!file.getName().toLowerCase().endsWith(extension.toLowerCase())) {
file = new File(file.getAbsolutePath().concat(extension));
}
if (file.exists()) {
if (file.canWrite()) {
if (JOptionPane.showConfirmDialog(null, "Do you really want to overwrite this file?", "Erasing file", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.NO_OPTION) {
file = null;
}
} else {
file = null;
JOptionPane.showMessageDialog(null, "Cannot write to the specified file!", "Error while opening the file", JOptionPane.ERROR_MESSAGE);
}
}
}
} else {
return null;
}
}
return file;
}
private static final long serialVersionUID = 1L;
}
EDIT: I tryed running my program on windows and everything works fine. Do you have knowledge of a platforme related problem concerning this class/method ?
Use your code inside a code block as bellow.
private void fileChooserMethod() {
EventQueue.invokeLater(new Runnable() {
#Override
public void run() {
javax.swing.JFileChooser fc_file_selector= new JFileChooser();
int response = fc_file_selector.showOpenDialog(null);
//your code here
}
});
}
Related
Problem in creating a new workspace in an Eclipse RCP application.
When the RCP application is launched, a dialog is prompted to ask the workspace location.
When the location is given, then there is error saying "Could not launch the product because the specified workspace cannot be created.
The specified workspace directory is either invalid or read-only".
I have followed the code from IDEApplication.java from eclipse, but still I am facing same issue.
Application code:
#SuppressWarnings("restriction")
public class MyRcpApplication implements IApplication
{
private static final String METADATA_PROJECTS_PATH = "/.plugins/org.eclipse.core.resources/.projects";
private static final String METADATA_ROOT = ".metadata";
private static final String COMMAND_ARG = "--container";
private static final String SYSTEM_PROPERTY_EXIT_CODE = "eclipse.exitcode";
private static final String WORKSPACE_VERSION_KEY = "org.eclipse.core.runtime";
private static final String VERSION_FILENAME = "version.ini";
private static final String WORKSPACE_VERSION_VALUE = "1"; //$NON-NLS-1$
public static final String METADATA_FOLDER = ".metadata"; //$NON-NLS-1$
private Shell shell;
/*
* (non-Javadoc)
*
* #see org.eclipse.equinox.app.IApplication#start(org.eclipse.equinox.app.IApplicationContext)
*/
#Override
public Object start(final IApplicationContext context)
{
Display display = PlatformUI.createDisplay();
Shell shell = display.getActiveShell();
try
{
// for backward compatibility we need to clear the workspace before start also
cleanUpTheWorkSpace();
boolean instanceLocationCheck = checkInstanceLocation(shell, context.getArguments());
if (!instanceLocationCheck)
{
MessageDialog.openError(shell, IDEWorkbenchMessages.IDEApplication_workspaceInUseTitle,
"Could not launch the product because the associated workspace is currently in use by another My Application.");
return IApplication.EXIT_OK;
}
int returnCode = PlatformUI.createAndRunWorkbench(display, new MyApplicationWorkbenchAdvisor());
if (returnCode == PlatformUI.RETURN_RESTART)
{
// eclipse.exitcode system property may be set to re-launch
if (IApplication.EXIT_RELAUNCH.equals(Integer.getInteger(SYSTEM_PROPERTY_EXIT_CODE)))
{
return IApplication.EXIT_RELAUNCH;
}
return IApplication.EXIT_RESTART;
}
// if application return code is exit clean up the workspace
// cleanUpTheWorkSpace();
return IApplication.EXIT_OK;
}
finally
{
if (display != null)
{
display.dispose();
}
Location instanceLoc = Platform.getInstanceLocation();
if (instanceLoc != null)
{
instanceLoc.release();
}
}
}
#SuppressWarnings("rawtypes")
private boolean checkInstanceLocation(final Shell shell, final Map arguments)
{
Location instanceLoc = Platform.getInstanceLocation();
if (instanceLoc == null)
{
MessageDialog.openError(shell, "Workspace is Mandatory", "IDEs need a valid workspace.");
return false;
}
// -data "/valid/path", workspace already set
if (instanceLoc.isSet())
{
// make sure the meta data version is compatible (or the user has
// chosen to overwrite it).
try
{
// Used to check whether are we launching My application from development environment or not
if (isDevLaunchMode(arguments))
{
return true;
}
// Used to check instance location is locked or not
if (instanceLoc.isLocked())
{
return false;
}
// we failed to create the directory.
// Two possibilities:
// 1. directory is already in use
// 2. directory could not be created
File workspaceDirectory = new File(instanceLoc.getURL().getFile());
if (workspaceDirectory.exists())
{
if (isDevLaunchMode(arguments))
{
return true;
}
MessageDialog.openError(
shell,
"Workspace Cannot Be Locked",
"Could not launch the product because the associated workspace at '" + workspaceDirectory.getAbsolutePath()
+ "' is currently in use by another Eclipse application");
}
else
{
MessageDialog
.openError(
shell,
"Workspace Cannot Be Created",
"Could not launch the product because the specified workspace cannot be created. The specified workspace directory is either invalid or read-only.");
}
}
catch (IOException e)
{
MessageDialog.openError(shell, "Internal Error", e.getMessage());
}
}
else
{
try
{
// -data #noDefault or -data not specified, prompt and set
ChooseWorkspaceData launchData = new ChooseWorkspaceData(instanceLoc.getDefault());
boolean force = false;
while (true)
{
URL workspaceUrl = promptForWorkspace(shell, launchData, force);
if (workspaceUrl == null)
{
return false;
}
// if there is an error with the first selection, then force the
// dialog to open to give the user a chance to correct
force = true;
try
{
// the operation will fail if the url is not a valid
// instance data area, so other checking is unneeded
if (instanceLoc.set(workspaceUrl, false))
{
launchData.writePersistedData();
writeWorkspaceVersion(workspaceUrl);
return true;
}
}
catch (IllegalStateException e)
{
MessageDialog
.openError(
shell,
IDEWorkbenchMessages
.IDEApplication_workspaceCannotBeSetTitle,
IDEWorkbenchMessages
.IDEApplication_workspaceCannotBeSetMessage);
return false;
}
// by this point it has been determined that the workspace is
// already in use -- force the user to choose again
MessageDialog.openError(shell, IDEWorkbenchMessages
.IDEApplication_workspaceInUseTitle,
IDEWorkbenchMessages.
IDEApplication_workspaceInUseMessage);
}
}
catch (IllegalStateException | IOException e)
{
}
}
return true;
}
private static void writeWorkspaceVersion(final URL defaultValue)
{
Location instanceLoc = Platform.getInstanceLocation();
if (instanceLoc.isReadOnly())
{
// MessageDialog.openError(shell,"Read-Only Dialog", "Location was read-only");
System.out.println("Instance Got Locked......");
}
if ((instanceLoc == null) || instanceLoc.isReadOnly())
{
return;
}
File versionFile = getVersionFile(instanceLoc.getURL(), true);
if (versionFile == null)
{
return;
}
OutputStream output = null;
try
{
String versionLine = WORKSPACE_VERSION_KEY + '=' + WORKSPACE_VERSION_VALUE;
output = new FileOutputStream(versionFile);
output.write(versionLine.getBytes("UTF-8")); //$NON-NLS-1$
}
catch (IOException e)
{
IDEWorkbenchPlugin.log("Could not write version file", //$NON-NLS-1$
StatusUtil.newStatus(IStatus.ERROR, e.getMessage(), e));
}
finally
{
try
{
if (output != null)
{
output.close();
}
}
catch (IOException e)
{
// do nothing
}
}
}
/*
* (non-Javadoc)
*
* #see org.eclipse.equinox.app.IApplication#stop()
*/
#Override
public void stop()
{
if (!PlatformUI.isWorkbenchRunning())
{
return;
}
final IWorkbench workbench = PlatformUI.getWorkbench();
final Display display = workbench.getDisplay();
display.syncExec(new Runnable()
{
#Override
public void run()
{
if (!display.isDisposed())
{
workbench.close();
}
}
});
}
private URL promptForWorkspace(final Shell shell, final ChooseWorkspaceData launchData, boolean force)
{
URL url = null;
do
{
new ChooseWorkspaceDialog(shell, launchData, false, force).prompt(force);
String instancePath = launchData.getSelection();
if (instancePath == null)
{
return null;
}
// the dialog is not forced on the first iteration, but is on every
// subsequent one -- if there was an error then the user needs to be
// allowed to
force = true;
// create the workspace if it does not already exist
File workspace = new File(instancePath);
if (!workspace.exists())
{
workspace.mkdir();
}
try
{
// Don't use File.toURL() since it adds a leading slash that Platform does not
// handle properly. See bug 54081 for more details.
String path = workspace.getAbsolutePath().replace(File.separatorChar, '/');
url = new URL("file", null, path); //$NON-NLS-1$
}
catch (MalformedURLException e)
{
MessageDialog
.openError(
shell,
IDEWorkbenchMessages
.IDEApplication_workspaceInvalidTitle,
IDEWorkbenchMessages
.IDEApplication_workspaceInvalidMessage);
continue;
}
}
while (!checkValidWorkspace(shell, url));
return url;
}
private boolean checkValidWorkspace(final Shell shell, final URL url)
{
String version = readWorkspaceVersion(url);
// if the version could not be read, then there is not any existing
// workspace data to trample, e.g., perhaps its a new directory that
// is just starting to be used as a workspace
if (version == null)
{
return true;
}
final int ide_version = Integer.parseInt(WORKSPACE_VERSION_VALUE);
int workspace_version = Integer.parseInt(version);
// equality test is required since any version difference (newer
// or older) may result in data being trampled
if (workspace_version == ide_version)
{
return true;
}
// At this point workspace has been detected to be from a version
// other than the current ide version -- find out if the user wants
// to use it anyhow.
String title = "My App Titile"; //$NON-NLS-1$
String message = "My App Message";
MessageBox mbox = new MessageBox(shell, SWT.OK | SWT.CANCEL
| SWT.ICON_WARNING | SWT.APPLICATION_MODAL);
mbox.setText(title);
mbox.setMessage(message);
return mbox.open() == SWT.OK;
}
private static String readWorkspaceVersion(final URL workspace)
{
File versionFile = getVersionFile(workspace, false);
if ((versionFile == null) || !versionFile.exists())
{
return null;
}
try
{
// Although the version file is not spec'ed to be a Java properties
// file, it happens to follow the same format currently, so using
// Properties to read it is convenient.
Properties props = new Properties();
FileInputStream is = new FileInputStream(versionFile);
try
{
props.load(is);
}
finally
{
is.close();
}
return props.getProperty(WORKSPACE_VERSION_KEY);
}
catch (IOException e)
{
IDEWorkbenchPlugin.log("Could not read version file", new Status( //$NON-NLS-1$
IStatus.ERROR, IDEWorkbenchPlugin.IDE_WORKBENCH,
IStatus.ERROR,
e.getMessage() == null ? "" : e.getMessage(), //$NON-NLS-1$,
e));
return null;
}
}
private static File getVersionFile(final URL workspaceUrl, final boolean create)
{
if (workspaceUrl == null)
{
return null;
}
try
{
// make sure the directory exists
File metaDir = new File(workspaceUrl.getPath(), METADATA_FOLDER);
if (!metaDir.exists() && (!create || !metaDir.mkdir()))
{
return null;
}
// make sure the file exists
File versionFile = new File(metaDir, VERSION_FILENAME);
if (!versionFile.exists()
&& (!create || !versionFile.createNewFile()))
{
return null;
}
return versionFile;
}
catch (IOException e)
{
// cannot log because instance area has not been set
return null;
}
}
#SuppressWarnings("rawtypes")
private static boolean isDevLaunchMode(final Map args)
{
// see org.eclipse.pde.internal.core.PluginPathFinder.isDevLaunchMode()
if (Boolean.getBoolean("eclipse.pde.launch"))
{
return true;
}
return args.containsKey("-pdelaunch"); //$NON-NLS-1$
}
/**
* Deletes all the available projects in the workspace
*/
private void cleanUpTheWorkSpace()
{
// this will be the
String[] commands = Platform.getCommandLineArgs();
if (commands != null)
{
List<String> args = Arrays.asList(commands);
if (args.contains(COMMAND_ARG))
{
// if project is in the root delete it.. it will delete associated metadata
IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
if (projects != null)
{
for (IProject project : projects)
{
try
{
project.delete(true, new NullProgressMonitor());
}
catch (CoreException e)
{
// msgHandler.post(MsgSeverity.ERROR, "Unable to clear the workspace");
}
}
}
// if project is not in the root but if its in the workspace delete the metadata too
File[] workSpaceFiles = Platform.getLocation().toFile().listFiles();
for (File file : workSpaceFiles)
{
if (METADATA_ROOT.equals(file.getName()))
{
File projectMeta = new File(file.getPath() + METADATA_PROJECTS_PATH);
if ((projectMeta != null) && projectMeta.exists())
{
File[] children = projectMeta.listFiles();
for (File child : children)
{
FileUtils.deleteQuietly(child);
}
}
}
/*
* else { FileUtils.deleteQuietly(file); }
*/
}
}
}
}
}
Try run Eclipse as administrator.
Your code is just calling
if (instanceLoc.isLocked())
{
return false;
}
to check if the workspace is locked, but is doing nothing to make the workspace locked so this will always fall through to the error code.
IDEApplication does this:
if (instanceLoc.lock()) {
writeWorkspaceVersion();
return null;
}
you need to do something similar.
I am trying to upload a file to a database (a .mp4 file to be specific). But when I run my code the file path is not yet chosen because, in the program a window pops up where you can select a file you want to upload. Is there a way to achieve this?
The problem I am having with FileInputStream is that it asks for a file path at the start of my program but the path is still uncertain at that point.
Greetings Pygesux
This is where I try to INSERT into the db
public void draw() {
open.draw();
openText.draw();
if (video != null) {
upload.draw();
uploadText.draw();
}
}
public void mouseClick() {
if (open.mouseOverMe()) {
selectInput("Select a file to process:", "fileSelected");
} else if (upload.mouseOverMe()) {
uploadFile();
}
}
public void fileSelect(File selection) {
video = selection;
}
public void uploadFile() {
try {
con = database.getConnect();
java.sql.PreparedStatement statement = con.prepareStatement("INSERT INTO filmpje (filmpje) VALUES (?)");
FileInputStream input = new FileInputStream(video);
statement.setBlob(1, input);
statement.executeUpdate();
}
catch (SQLException e) {
e.printStackTrace();
}
}
Why you do not create FileInputStream after the path is chosen?
Make a method, that take path, and then creates the FileInputStream, and do other job. Call this method after you know your path, after user eneter it, and accept by pressing button/enter (it is your app logic).
I think you're trying to use selectInput() correct? The reference example is not super clear. The program continues to run while the user selects a file, so you get an error if you try to run code that requires the filename. Here's an example that tests if the file is set yet or not. You would need to update it for your particular needs:
String input;
void setup() {
size(500,200);
selectInput("Select a file...", "fileSelector");
}
void draw() {
background(255);
fill(0);
noStroke();
if (input == null) {
text("No file selected.", 20,height/2);
}
else {
text(input, 20,height/2);
}
}
void fileSelector(File selection) {
if (selection == null) {
// window closed or user hit cancel button
}
else {
input = selection.getAbsolutePath();
}
}
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How can a Java program use files inside the .jar for read and write?
How do I write to a .txt file from a JAR java compiled project?
When I run my projects, it doesn't give errors, but it just doesn't write to the .txt inside JAR file.
I make the JAR file using:
netbeans clean /build tool
Code:
public class FileIO {
private File file;
private Scanner filescScanner, lineScanner;
private PrintWriter fileWriter;
private String[][] data;
public FileIO () {
data = new String[100][2];
}
public String[][] getLineScores(){
return this.loadHighscores(this.getClass().getResourceAsStream("LineHighscores.txt"));
}
public String[][] getTimeScores(){
return this.loadHighscores(this.getClass().getResourceAsStream("TimeHighscores.txt"));
}
public void setLineScores( String name,String lines ){
boolean found= false;
data = this.getLineScores();
for(int i = 0; i<data.length && !found ; i++){
if(data[i][0] == null || "Niemand".equals(data[i][0])){
data[i][0]=name;
data[i][1]=lines;
found=true;
}
}
this.saveHighscores(this.getClass().getResource("LineHighscores.txt"),data);
}
public void setTimeScores(String time, String name){
boolean found= false;
data = this.getLineScores();
for(int i = 0; i<data.length && !found ; i++){
if(data[i][0] == null || "Niemand".equals(data[i][0])){
data[i][0]=name;
data[i][1]=time;
found=true;
}
}
this.saveHighscores(this.getClass().getResource("TimeHighscores.txt"),data);
}
private String[][] loadHighscores( InputStream resourceStream){
int x=0;
String test = "";
try{
filescScanner = new Scanner(resourceStream);
}
catch(Exception ioe){
System.err.println(ioe);
}
if (filescScanner.hasNext()){
while(filescScanner.hasNextLine()&& x<100) {
lineScanner = new Scanner(filescScanner.nextLine());
lineScanner.useDelimiter("-/-");
data[x][0]=lineScanner.next();//name
data[x][1]=lineScanner.next();//data
x++;
}
lineScanner.close();
filescScanner.close();
}
else{
data[0][0] = "Niemand";
data[0][1] = "0";
}
return data;
}
private void saveHighscores( URL resourceStream, String[][] data){
int x=0;
try {
file = new File(resourceStream.toURI());
} catch (URISyntaxException ex) {
Logger.getLogger(FileIO.class.getName()).log(Level.SEVERE, null, ex);
}
try {
fileWriter = new PrintWriter(file);
} catch (FileNotFoundException ex) {
Logger.getLogger(FileIO.class.getName()).log(Level.SEVERE, null, ex);
}
if(data.length>x){
while(data.length>x && data[x][0] != null ){
fileWriter.println(data[x][0]+"-/-"+data[x][1]);
x++;
}
fileWriter.close();
}
}
public static void main(String[] args){
FileIO file = new FileIO();
file.setLineScores("55555555", "KoenKevin");
}
}
You cannot do that, and even if you could do that, it is not recommendable: write to a location outside of the jar.
Jar is an archive, which is meant to be unchanged. If you need your jar (application) to write something, write to an external source.
I suggest you make a separate folder and make your application point to that folder and do all your external activity there.
When you are trying to write a text file inside a jar, java is not recognizing absolute path to text file.
it will be something like
C:User/adom/documents/jarName.jar!/fileName.txt
This is not a absolute path so file could not be written. Try writing file externally.
I have a directory that contains a lot of files. I want to delete the entire directory as well as all the files in it.
I want my code to wait until every File in that directory (including the directory itself) is deleted before the next command is executed.
How do i wait?
My code is
public void wipeMemoryCard()
{
File deleteMatchingFile = new File(Environment
.getExternalStorageDirectory().toString());
try {
filenames = deleteMatchingFile.listFiles();
if (filenames != null && filenames.length > 0)
{
content = true;
for (File tempFile : filenames)
{
if (tempFile.isDirectory())
{
wipeDirectory(tempFile.toString());
tempFile.delete();
}
else
{
File file = new File(tempFile.getAbsolutePath());
file.delete();
}
}
}
else
{
deleteMatchingFile.delete();
Toast("No files to Delete");
}
}
catch (Exception e)
{
e.printStackTrace();
}
if(content == true)
{
if (filenames == null && filenames.length == 0)
{
Toast("Files Deleted");
}
}
}
private static void wipeDirectory(String name) {
File directoryFile = new File(name);
File[] filenames = directoryFile.listFiles();
if (filenames != null && filenames.length > 0)
{
for (File tempFile : filenames)
{
if (tempFile.isDirectory())
{
wipeDirectory(tempFile.toString());
tempFile.delete();
}
else
{
File file = new File(tempFile.getAbsolutePath());
file.delete();
}
}
} else
{
directoryFile.delete();
}
}
You should not run this on the UI thread. If the file deletion takes too long, the system will pop up an "Application Not Responding" error. You can do this with an AsyncTask. The documentation shows a simple way to use this to pop up a "please wait" dialog, do the time-consuming work in the background, and then dismiss the dialog.
P.S. Your method name is kind of scary! :)
You Should user Handler for this so when all files gets deleted it will send message to handler to the next task that you want to perform .
see this link for handler..
http://www.tutorialforandroid.com/2009/01/using-handler-in-android.html
Hope you are asking about this ....
public static void DeleteRecursive(String filename) {
File file = new File(filename);
if (!file.exists())
return;
if (!file.isDirectory()) {
file.delete();
return;
}
String[] files = file.list();
for (int i = 0; i < files.length; i++) {
DeleteRecursive(filename + "/" + files[i]);
}
file.delete();
}
Okay, I'm trying to create a custom client for Minecraft (don't worry, my question has nothing to do with Minecraft in particular), and I added an abstract class to manage a configuration file using Java's built-in Properties system. I have a method that loads a properties file or creates it if it doesn't already exist. This method is called at the beginning of all my other methods (although it only does anything the first time its called).
The properties file gets created just fine when I run Minecraft the first time, but somehow when I run it the second time, the file gets blanked out. I'm not sure where or why or how I'm wiping the file clean, can someone please help me? Here's my code; the offending method is loadConfig():
package net.minecraft.src;
import java.util.*;
import java.util.regex.*;
import java.io.*;
/**
* Class for managing my custom client's properties
*
* #author oxguy3
*/
public abstract class OxProps
{
public static boolean configloaded = false;
private static Properties props = new Properties();
private static String[] usernames;
public static void loadConfig() {
System.out.println("loadConfig() called");
if (!configloaded) {
System.out.println("loading config for the first time");
File cfile = new File("oxconfig.properties");
boolean configisnew;
if (!cfile.exists()) {
System.out.println("cfile failed exists(), creating blank file");
try {
configisnew = cfile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
configisnew=true;
}
} else {
System.out.println("cfile passed exists(), proceding");
configisnew=false;
}
FileInputStream cin = null;
FileOutputStream cout = null;
try {
cin = new FileInputStream(cfile);
cout = new FileOutputStream(cfile);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
if (!configisnew) { //if the config already existed
System.out.println("config already existed");
try {
props.load(cin);
} catch (IOException e) {
e.printStackTrace();
}
} else { //if it doesn't exist, and therefore needs to be created
System.out.println("creating new config");
props.setProperty("names", "oxguy3, Player");
props.setProperty("cloak_url", "http://s3.amazonaws.com/MinecraftCloaks/akronman1.png");
try {
props.store(cout, "OXGUY3'S CUSTOM CLIENT\n\ncloak_url is the URL to get custom cloaks from\nnames are the usernames to give cloaks to\n");
cout.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
String names = props.getProperty("names");
System.out.println("names: "+names);
try {
usernames = Pattern.compile(", ").split(names);
} catch (NullPointerException npe) {
npe.printStackTrace();
}
System.out.println("usernames: "+Arrays.toString(usernames));
configloaded=true;
}
}
public static boolean checkUsername(String username) {
loadConfig();
System.out.println("Checking username...");
for (int i=0; i<usernames.length; i++) {
System.out.println("comparing "+username+" with config value "+usernames[i]);
if (username.startsWith(usernames[i])){
System.out.println("we got a match!");
return true;
}
}
System.out.println("no match found");
return false;
}
public static String getCloakUrl() {
loadConfig();
return props.getProperty("cloak_url", "http://s3.amazonaws.com/MinecraftCloaks/akronman1.png");
}
}
If it's too hard to read here, it's also on Pastebin: http://pastebin.com/9UscXWap
Thanks!
You are unconditionally creating new FileOutputStream(cfile). This will overwrite the existing file with an empty one. You should only invoke the FileOutputStream constructor when writing a new config file.
if (configloaded)
return;
File cfile = new File("oxconfig.properties");
try {
if (cfile.createNewFile()) {
try {
FileOutputStream cout = new FileOutputStream(cfile);
props.setProperty("names", "oxguy3, Player");
props.setProperty("cloak_url", "http://...");
...
cout.flush();
} finally {
cout.close();
}
} else {
FileInputStream cin = new FileInputStream(cfile);
try {
props.load(cin);
} finally {
cin.close();
}
}
configloaded=true;
} catch(IOException ex) {
e.printStackTrace();
}