Does File.delete () remove a File object pointer?

My colleagues and I have an argument about how the method File.delete()works in Java.

In our code:

File outFile = new File("/dir/name.ext");
if(outFile.exists())
    outFile.delete();

FileInputStream inStream = new FileInputStream(outFile);

WriteFile.writeFile(inStream); // Writes the actual file

I cannot include the whole method object writeFilehere for security reasons, but after creating the necessary database object, it performs the following action:

BufferedOutputStream out = null;

Object[] args = {"an_encrypted_data_clob_name_in_the_database"};
Class[] argTypes = {Class.forName("java.lang.String")};
Object result = WSCallHelper.jdbcCall(null, rs, "getCLOB", args, argTypes);
CLOB clob = (CLOB)result;
out = new BufferedOutputStream(clob.getAsciiOutputStream());

byte[] buffer = new byte[512];
int bytesRead = -1;

while((bytesRead = inStream.read(buffer)) > -1)
    out.write(buffer, 0, bytesRead);

I know this is a bit unclear, but the general point is that it creates AsciiOutputStreamfor Clob(yes, it should be Clob) and writes it to an object inStreamthat is passed from the previous method.

, - File.delete();, , , . , , , , outFile, inStream outFile inStream .

, ? , delete() , File, .

+4
1

java.io.File . .

.

, .

File ; , File, .

File, , String.

delete , .

, .

java.io.FileDescriptor:

, [& hellip;].

/ , File, FileOutputStream(File) :

, File. FileDescriptor.

[& hellip;] , - , FileNotFoundException.

, , , FileOutputStream, String File, , , File:

public FileOutputStream(File file, boolean append)
    throws FileNotFoundException
{
    String name = (file != null ? file.getPath() : null);
    SecurityManager security = System.getSecurityManager();
    if (security != null) {
        security.checkWrite(name);
    }
    if (name == null) {
        throw new NullPointerException();
    }
    if (file.isInvalid()) {
        throw new FileNotFoundException("Invalid file path");
    }
    this.fd = new FileDescriptor();
    fd.attach(this);
    this.append = append;
    open(name, append);
}

, java.io.File .; )

, - , - , File ; ergo, File , .

+5

All Articles