Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 51 additions & 24 deletions java/src/main/java/com/genexus/util/GXFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,31 +209,58 @@ public boolean create(InputStream input, boolean overwrite) {
return ErrCode == 0;
}

public void delete() {
if (sourceSeted()) {
resetErrors();
try {
if (!(FileSource.isFile() && FileSource.exists())) {
ErrCode = 2;
ErrDescription = "The file couldn't be deleted; file does not exist";
} else {
try {
ret = FileSource.delete();
if (!ret) {
setUnknownError();
}
} catch (SecurityException e) {
ErrCode = 100;
ErrDescription = e.getMessage();
}
}
} catch (Exception e) {
setUnknownError(e);
}
}
}
public void delete() {
if (sourceSeted()) {
resetErrors();
try {
if (!(FileSource.isFile() && FileSource.exists())) {
ErrCode = 2;
ErrDescription = "The file couldn't be deleted because it does not exist";
return;
}

try {
if (fileWriter != null) {
fileWriter.close();
fileWriter = null;
}
if (lineIterator != null) {
lineIterator.close();
lineIterator = null;
}
if (this.getStream() != null) {
this.getStream().close();
}
} catch (Exception ignored) {}

System.gc();

boolean ret = FileSource.delete();
if (!ret) {
try {
String filePath = FileSource.getFileInstance().getAbsolutePath();
ProcessBuilder pb;
if (System.getProperty("os.name").toLowerCase().contains("win")) {
pb = new ProcessBuilder("cmd.exe", "/c", "del /F /Q \"" + filePath + "\"");
} else {
pb = new ProcessBuilder("rm", "-f", filePath);
}
pb.start().waitFor();
if (FileSource.exists()) {
setUnknownError();
}
} catch (Exception e) {
setUnknownError(e);
}
}
} catch (Exception e) {
setUnknownError(e);
}
}
}


public boolean exists() {
public boolean exists() {
if (sourceSeted()) {
try {
resetErrors();
Expand Down
Loading