Hey

I have this code

FileUtils.forceDelete(new File(nombreprograma+".zip");
FileUtils.forceDelete(new File(nombreprograma+"/"+nombrebmp+".bmp"));

Deleting the zip inside of the root works perfect but for some reason the BMP inside of a folder, doesnt.

The error it gives is that it cannot delete the file, nothing else.

Any tips?

3
Contributors
29
Replies
34
Views
5 Years
Discussion Span
Last Post by dantinkakkar
Featured Replies
• 1

try the same delete in a separate app, not the one you're writing it in, because you having still the reference to the file still open is most likely the problem. if you try with a separate app to remove it, you can test whether there's something wrong with your …

• 2

In my main, when trying to delete it, it simply says unable to delete. Nothing else.

Have you tried placing another BMP file and then trying to delete it? There may be a problem with the specific BMP file. Just give it a try, and if it still doesn't get erased, re-post; and I'll see what I can do.

Have you tried placing another BMP file and then trying to delete it? There may be a problem with the specific BMP file. Just give it a try, and if it still doesn't get erased, re-post; and I'll see what I can do.

Its a BMP I generate running the program (at mid point). But I dont use anything else except putting it in that zip file.

After generating the BMP file, did you close your Output Stream?

Not closing may be the cause.

Edited by dantinkakkar: n/a

After generating the BMP file, did you close your Output Stream?

Not closing may be the cause.

When writing the image, I use ImageIO.write ....Not sure if I can close that or/and if that was what you ment...

No, you don't close that. It's different. A little more code, please?

And before that, just try deleting the file with a separate piece of code after writing to it once. Like, try deleting it programmatically in a different program. If that doesn't work, give a little more code - the writing part.

Edited by dantinkakkar: n/a

try the same delete in a separate app, not the one you're writing it in, because you having still the reference to the file still open is most likely the problem.

if you try with a separate app to remove it, you can test whether there's something wrong with your 'remove' implementation or whether the problem is located elsewhere.

No, you don't close that. It's different. A little more code, please?

And before that, just try deleting the file with a separate piece of code after writing to it once. Like, try deleting it programmatically in a different program. If that doesn't work, give a little more code - the writing part.

(Lunch break :P )

There is also another file inside of another dir I cannot delete. It is a bin binary file and this seems to be closed (all streams in that part of code are close). Could it be something else?

Thanks and ill try to give you for info. Can't give you code as like I mentioned I'm on my lunch break and not at the PC

The code to delete the files in a separate program?

Edited by dantinkakkar: n/a

(Lunch break :P )

There is also another file inside of another dir I cannot delete. It is a bin binary file and this seems to be closed (all streams in that part of code are close). Could it be something else?

Thanks and ill try to give you for info. Can't give you code as like I mentioned I'm on my lunch break and not at the PC

firstly: sure, you can have it open in notepad (or any other editor), ... multiple reasons why.
about giving you the code: no, we can not. not only would we be in violation of forum rules, but so far, you have asked for nothing that a simple google query would not be able to help you with.

also, you did not provide with enough code for us to check whether or not you can have an error of which you do not get a message because you don't handle an exception.

try what we suggested so far, or show us some more code so we might be able to see where you're going wrong.

Quoting on a cell phone is a bitch so ill just reply as normal

Dant - What I use to delete the BMP is that simple function from the Apache commons library. And the BMP is generated in the same program as I call that simple function.

Stul - First, calm the fuck down. That's first off. I haven't in any moment demanded anything or replied with a attitude until now. If you notice, I generate a BMP. Why on earth would I open that in Notepad?

More so, I never said "give me code". I have code and I know what it does but it won't delete it. I tried with the delete function in the File class as well, in case you think I still NEED code. I asked for tips why my code might not work

And last, I just said I went on my lunch break and that's why I couldn't put any code. As soon as I get back ill put some code.

Here is a tip for you: Next time instead of treating everyone with a attiude and like newcomers, READ THE ENTIRE THREAD. It will help you not look like a fool.

Thanks to the rest helping out :)

wow-wee ... aren't we the adult. next time READ the actual posts, not just the ones you like

Can you tell me what Operating System are you using? Like, I'm asking because you're saving and deleting from the "root", if I'm interpreting what you said correctly. If it's Linux, we do have a problem on our hands here and I can understand the usage of forceDelete . I dunno why you would do that on win32 if you're saving to the root: taking the root as Local Disk C:

Edited by dantinkakkar: n/a

(Lunch break :P )

There is also another file inside of another dir I cannot delete. It is a bin binary file and this seems to be closed (all streams in that part of code are close). Could it be something else?

I was referring tho THAT file, not your bmp.

Can't give you code as like I mentioned I'm on my lunch break and not at the PC

you specifically ASKED for code LIKE YOU MENTIONED. so yes, you DID ask for code.

Stul - First, calm the fuck down. That's first off. I haven't in any moment demanded anything or replied with a attitude until now.

very polite way to talk to those who are willing to VOLUNTEER helping you solve what you obviously can't get to work yourself. what did I do that wasn't calm? ask for a bit more code then those two lines? you said yourself: I create that file in this class, so off course it's possible that there is still a reference to that file open which would *surprise surprise* make sure you can't delete the file. (who would have figured that???)
I simply refered to this: The forum rules. which, yes, we would be breaking by 'giving you' complete code.

Here is a tip for you: Next time instead of treating everyone with a attiude and like newcomers, READ THE ENTIRE THREAD. It will help you not look like a fool.

no, Jack-in-the-box, here's a tip for you: next time, be smart enough to notice that I DID read the entire thread and apparently, unlike you, I did read what you wrote.
for the record: I spent part of MY lunch break looking over your problem and what the cause may be.

But, you're right ... apparently trying to help you solve your mess does make me look like a fool. Might better quit before I actually succeed at it, wouldn't you agree?

Counter balance negative vote that was given without reason
Horrible attitude and not helpful at all.

*nowords*

Let's just try to solve his problem, and ignore the blabbity blap. That's what I tried to explain to him, that he might've left an output stream open; but he does need to provide the image-writing code for us to understand whatever his problem is: my point is, @riahc3 is not explaining his problem correctly.

Stul

I especifically said it was a binary file for that reason; so noone thinks it is a text file that can be opened in another program. Only our PLC can read it.

I am asking you, no fuck that, begging you to quote me where I said "can I have the code to" or "do you have code" or ANYTHING that asks for code. As a matter of fact, noone has said any code and the only logical question is if my OutputStream was closed. But please, go ahead, quote me.

I simply replied to your comment, which you obviously did not read what I posted, because if you did you would know it is a binary file, I was just going away on my lunch break and I did not ask for code at all, just tips on what it may be. And AFAIK you haven't volunteered to help out anyone, as you simple came into this thread with a attitude on your mine.

Here's another tip for you: Don't have anything useful to say in a polite matter? Don't post at all. Simple as that.

Last post towards you if you have nothing helpful to say.

Dant

Alright, I'm getting back to work right now so ill analize some of the code and see if I can post what you need that you might see where the problem is. 15-20 minutes. Thank you very much for your help.

Hey, chill riahc, don't turn it into a battlezone. Just post your code, and I'll help you out with it! :)

Hey, chill riahc, don't turn it into a battlezone. Just post your code, and I'll help you out with it!

I apoligize. Just really annoys me when "veteren" members try to treat everyone else like newcomers.

Here is the code to that binary file:

public class Generar_Binario
{

public void GenerarBinario(String corte)
{
File fe = new File(corte);
File fd = new File("Path1.bin");
int i=0;

try
{
FileOutputStream file_outpute = new FileOutputStream(fe);
FileOutputStream file_outputd = new FileOutputStream(fd);
DataOutputStream data_oute=new DataOutputStream(file_outpute);
DataOutputStream data_outd=new DataOutputStream(file_outputd);
BinaryOut ue=new BinaryOut(data_oute);// Parte de la liberia
BinaryOut ud=new BinaryOut(data_outd);// Parte de la liberia

for (i = 1; i < Globales.size_array; i++)
{
ud.write(Long.reverseBytes(Double.doubleToRawLongBits(Globales.pos_servo_1[i])));
ud.write(Long.reverseBytes(Double.doubleToRawLongBits(Globales.pos_servo_2[i])));
}

ud.close();

Globales.tabla_st3[0]=20;
Globales.tabla_st3[1]=100;
Globales.tabla_st3[2]=Globales.size_array*0.004;
//Globales.tabla_st3[3]=0;
Globales.tabla_st3[4]=60;

for (i=0; i <=Globales.tabla_st3.length ; i++)
{
if(Globales.tabla_st3[i]==Globales.CODIGO_FIN)
{
ue.write(Integer.reverseBytes((int)Globales.tabla_st3[i]));
break;
}
ue.write(Integer.reverseBytes((int)Globales.tabla_st3[i]));
}

ue.close();
ud.close();

//Mas lineas

file_outpute.close();
file_outputd.close();
data_oute.close();
data_outd.close();
}
catch (FileNotFoundException e)
{
System.out.println("ERROR: No se puede encontrar el fichero: (" + e.getLocalizedMessage() + ")");
} catch (IOException e)
{
System.out.println("ERROR: No se puede cerrar bien el fichero: (" + e.getLocalizedMessage() + ")");

}

}
}

As you see on this end, I close it.........Now when I zip it up:

public void CrearEstructura(String archivo,int i)
{
File ff=new File("Path1.bin");
new File(archivo+"/"+archivo).mkdirs();
File bin=new File(archivo+".bin");
String[] trozos=archivo.split("_");
String archivobmp=trozos[0]+"_"+trozos[1]+"_"+trozos[2];
System.out.println("El string resultante es: " + archivobmp);
File bmp=new File(archivobmp+".bmp");
bmp.renameTo(new File(archivo+"/"+archivobmp+".bmp"));
ff.renameTo(new File(archivo+"/"+archivo+"/"+ff.getName()));
bin.renameTo(new File(archivo+"/"+archivo+"/"+bin.getName()));

}

First the structure I create for inside the zip (The variable "i" isnt implanted yet as I need for for something later)

Zipping it up:

public boolean zipFiles(String srcFolder, String destZipFile)
{
boolean result=false;
try
{
zipFolder(srcFolder,destZipFile);
result=true;
}
catch(Exception e)
{
System.out.println("ERROR: Ha ocurrido un error durante la compresion ( " + e.getLocalizedMessage() + " )");
}
finally
{
return result;
}
}

And thats it.......I dont think there is nothing else I may have missed.

BTW, Im posting the binary file as I think the problem is the same with the BMP correct?

Always this is on a Windows machine. By root, I ment the root of the project where everything is saved. My mistake for not clearing that up.

In my main, when trying to delete it, it simply says unable to delete. Nothing else.

There're two things that I'd like to ask, now that you've cleared that up:

1. Did you try deleting with a separate piece of code in a separate file, that is, instead of doing it in the same program?

2. The method zipFolder(), does it close up everything?

There're two things that I'd like to ask, now that you've cleared that up:

1. Did you try deleting with a separate piece of code in a separate file, that is, instead of doing it in the same program?

2. The method zipFolder(), does it close up everything?

1. No I didnt. Do I do it with a absolute pathname (as in: new File("C:\\folder\\anotherfolder\\thefile.bin") or do I do it relative? Absolute would obviously make my life easier :P
2. Yes, sorry about that. zipFolder closes everything also too.

Edited by riahc3: n/a

This code in a complete other program:

import java.io.File;

public class BorrarArchivosFunciones {

/**
* @param args
*/
public static void main(String[] args)
{

File f=new File("C:\\Archivos de programa\\MyEclipse for Spring\\Common\\plugins\\com.genuitec.eclipse.easie.tomcat.myeclipse_9.0.0.me201109141806\\tomcat\\bin\\200000110_1_135046720_1\\200000110_1_135046720.bmp");
if (f.delete()==true)
{
System.out.println("Deleted");
}
else
{
System.out.println("Not deleted");
}
}

}

Perfectly deletes the file.

:\ lemme think

Edited by dantinkakkar: n/a

Do it using absolute paths.

Jumped the gun :P and did it with absolute paths and it worked

So now the question is why can't I do it in my original program?

:\ lemme think

Same thing I thought every time I thought of this problem :P

Thank you for the help always :)

Edited by riahc3: n/a

Since it is working in a separate program, the only and obvious reason due to which the file is not getting erased is since the OutputStream is not closing properly. What I suggest is that you write a separate module for deleting the code and make it executable. Then, access the application with your code so that it deletes all of that in a separate process and the file is not in use any longer. Otherwise, put in a bit of work and find out what is not closing. I suspect that the problem lies where you're using pre-built libraries. Something is not closing the output stream.

@riahc, do the following:

switch e.getLocalizedMessage() with e.printStackTrace()
for a more complete error message, and convey the exact error message! :)

Since I couldnt get it to work using Route A, I used Route B and it solved the problem.

There is more than one way to skin a cat they say :P

Thanks dantinkakkar

@riahc, do the following:

switch e.getLocalizedMessage() with e.printStackTrace()
for a more complete error message, and convey the exact error message!

Great minds thing alike :P

I use those 2 methods when my web service has a issue and using that it sends a email to me with the errors.

It is solved so thank you.

Thank stul. :D