B4J Question Unexpected Result from File.ReadString and File.ReadBytes on UTF-8 Text File

B4XDev

Member
Licensed User
I have a text file (UTF-8) being used as a preferences file. When I read from it, I get some strange marks where blank lines are.

The prefs.ini file

debug=off

MYDIR=https://MYDIR.net/
MYSERVER=https://MYSERVER.com/
remoteServer=[MYDIR]

LOCAL_SERVER=http://mywebsite.net/
API_SERVER=[MYSERVER]api/

#Forms Manager settings
licenseServer=[LOCAL_SERVER]
licServerPath=[licenseServer]licserv/

formsLibrary=https://MYDIR.net/templates/
FORMS_LIBRARY_ext1=[formsLibrary]ext1/
FORMS_LIBRARY_ext2=[formsLibrary]ext2/
FORMS_LIST=list.txt

adminKey=jdshfgkj98ys8dfs98hskujh

#server app data files
DAILY_MESSAGE=[API_SERVER]motd
SERVER_FILES=/usr/local/

#Local admin/dev settings
myNetworkDir=c:\Apache24\htdocs\
FILE_DIR=[licenseServer]files\data\
COMPANY_DIR=[myNetworkDir]files\data\
DATAFILES=[myNetworkDir]files\datafiles\
logFile=install.log
TEMPLATES=[myNetworkDir]files\ext1\
TEMPLATES_V1=[TEMPLATES]
TEMPLATES_V2=[myNetworkDir]files\ext2\

LICENSES=[myNetworkDir]files\licenses\
MATCH_CACHE=[DATAFILES]match_cache.txt
LOCAL_CACHE=[COMPANY_DIR]cache.txt

CACHE=[licenseServer]files/data/cache.txt

DATA_DIR=[myNetworkDir]files\data\
DATA_CACHE_MAP=[myNetworkDir]files\cache.map
MATCH_CACHE_MAP=[myNetworkDir]files\match_cache.map

#Better name for what these files are
CODE_FILES=[licenseServer]files/datafiles/
API=[licenseServer]files/
MATCH_CACHE_FILE=[MYDIR]data/match_cache.txt

logFile=install.log

#Want to update server license?
doUpdate=true

Reading it with ReadMap fails, of course. But reading it with ReadString and ReadBytes provides unexpected results:

Using File.ReadBytes

debug=off
~l065898263:
MYDIR=https://MYDIR.net/
MYSERVER=https://MYSERVER.com/
remoteServer=[MYDIR]
~l065898263:
LOCAL_SERVER=http://mywebsite.net/
API_SERVER=[MYSERVER]api/
~l065898263:
#Forms Manager settings
licenseServer=[LOCAL_SERVER]
licServerPath=[licenseServer]licserv/
~l065898263:
formsLibrary=https://MYDIR.net/templates/
FORMS_LIBRARY_ext1=[formsLibrary]ext1/
FORMS_LIBRARY_ext2=[formsLibrary]ext2/
FORMS_LIST=list.txt
~l065898263:
adminKey=jdshfgkj98ys8dfs98hskujh
~l065898263:
#server app data files
DAILY_MESSAGE=[API_SERVER]motd
SERVER_FILES=/usr/local/
~l065898263:
#Local admin/dev settings
myNetworkDir=c:\Apache24\htdocs\
FILE_DIR=[licenseServer]files\data\
COMPANY_DIR=[myNetworkDir]files\data\
DATAFILES=[myNetworkDir]files\datafiles\
logFile=install.log
TEMPLATES=[myNetworkDir]files\ext1\
TEMPLATES_V1=[TEMPLATES]
TEMPLATES_V2=[myNetworkDir]files\ext2\
~l065898263:
LICENSES=[myNetworkDir]files\licenses\
MATCH_CACHE=[DATAFILES]match_cache.txt
LOCAL_CACHE=[COMPANY_DIR]cache.txt
~l065898263:
CACHE=[licenseServer]files/data/cache.txt
~l065898263:
DATA_DIR=[myNetworkDir]files\data\
DATA_CACHE_MAP=[myNetworkDir]files\cache.map
MATCH_CACHE_MAP=[myNetworkDir]files\match_cache.map
~l065898263:
#Better name for what these files are
CODE_FILES=[licenseServer]files/datafiles/
API=[licenseServer]files/
MATCH_CACHE_FILE=[MYDIR]data/match_cache.txt
~l065898263:
logFile=install.log
~l065898263:
#Want to update server license?
doUpdate=true

Using File.ReadString

debug=off
~l065898266:
MYDIR=https://MYDIR.net/
MYSERVER=https://MYSERVER.com/
remoteServer=[MYDIR]
~l065898266:
LOCAL_SERVER=http://mywebsite.net/
API_SERVER=[MYSERVER]api/
~l065898266:
#Forms Manager settings
licenseServer=[LOCAL_SERVER]
licServerPath=[licenseServer]licserv/
~l065898266:
formsLibrary=https://MYDIR.net/templates/
FORMS_LIBRARY_ext1=[formsLibrary]ext1/
FORMS_LIBRARY_ext2=[formsLibrary]ext2/
FORMS_LIST=list.txt
~l065898266:
adminKey=jdshfgkj98ys8dfs98hskujh
~l065898266:
#server app data files
DAILY_MESSAGE=[API_SERVER]motd
SERVER_FILES=/usr/local/
~l065898266:
#Local admin/dev settings
myNetworkDir=c:\Apache24\htdocs\
FILE_DIR=[licenseServer]files\data\
COMPANY_DIR=[myNetworkDir]files\data\
DATAFILES=[myNetworkDir]files\datafiles\
logFile=install.log
TEMPLATES=[myNetworkDir]files\ext1\
TEMPLATES_V1=[TEMPLATES]
TEMPLATES_V2=[myNetworkDir]files\ext2\
~l065898266:
LICENSES=[myNetworkDir]files\licenses\
MATCH_CACHE=[DATAFILES]match_cache.txt
LOCAL_CACHE=[COMPANY_DIR]cache.txt
~l065898266:
CACHE=[licenseServer]files/data/cache.txt
~l065898266:
DATA_DIR=[myNetworkDir]files\data\
DATA_CACHE_MAP=[myNetworkDir]files\cache.map
MATCH_CACHE_MAP=[myNetworkDir]files\match_cache.map
~l065898266:
#Better name for what these files are
CODE_FILES=[licenseServer]files/datafiles/
API=[licenseServer]files/
MATCH_CACHE_FILE=[MYDIR]data/match_cache.txt
~l065898266:
logFile=install.log
~l065898266:
#Want to update server license?
doUpdate=true

What are the lines that begin with the tilde (~)?! How do I get a clean input of my text file?
 

B4XDev

Member
Licensed User
I iterated through a File.ReadList() version, and those lines come up as .length = 0... So, everything seems to be as you say. ?

Thank you!
 
Upvote 0
Top