B4J Question File.Exists("","") return true using JRE 26

xulihang

Well-Known Member
Licensed User
Longtime User
Hi,

I am encountering an issue after upgrading to JRE 26.

If I pass an empty string for File.Exists, it returns true. While in previous versions like JRE 23, it returns False.

B4X:
Dim dc As DirectoryChooser
dc.Initialize
Dim path As String = dc.Show(MainForm)
If File.Exists(path,"") Then 'empty string if no file selected
   Log("do something")
End If
 

xulihang

Well-Known Member
Licensed User
Longtime User
Setting the empty working directory then leads to failure to start a program via shell.

B4X:
private serverShell as Shell
If File.Exists(WorkFolderTextField.Text,"") Then
    serverShell.WorkingDirectory = WorkFolderTextField.Text
End If
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Setting the empty working directory then leads to failure to start a program via shell.

B4X:
If WorkFolderTextField.Text <> "" Then
  
    If File.Exists(WorkFolderTextField.Text,"") Then
        serverShell.WorkingDirectory = WorkFolderTextField.Text
    End If
  
Else
...
End If

(It is always better to use variables rather than directly using the `Text` property of the views).
 
Upvote 0

xulihang

Well-Known Member
Licensed User
Longtime User
I created a sub and replace all the File.Exists with this Sub.

B4X:
Public Sub Exists(dir As String,filename As String) As Boolean
    Dim path As String = File.Combine(dir,filename)
    If path = "" Then
        Return False
    Else
        Return File.Exists(dir,filename)
    End If
End Sub
 
Upvote 0
Top