UWP File system

32 views
Skip to first unread message

mcell...@gmail.com

unread,
Feb 13, 2017, 7:35:04 AM2/13/17
to CodenameOne Discussions
Hi, I decided to try and create a uwp version of my codename one app but encountered some errors (which don't occur on simulator or ios or old win pohne builds). 

To try and solve the issue I have been opening the codename one generated source code in visual studio and trying to debug - this isn't easy as there actually isn't much source code to debug in as it all seems to be in a libary - and I'm not sure the best way to output info to the console window so currently, as you will see in this example I am using dialogs to output information back to me.

Anyway, this code is very straightforward - create a file and try and read it back. It seems that the path to the file is file:///Local:\testfile.txt - it appears to create both streams (ie no exe and no null) but there is no file created an it cannot read anything back.

It seems pretty basic code but is not working. Any thoughts? 

Thanks, Paul

Dialog.show("TEST", "Starting file test", "Ok", null);
String fileName = FileSystemStorage.getInstance().getAppHomePath() +  FileSystemStorage.getInstance().getFileSystemSeparator() + "testfile.txt";

Dialog.show("TEST", "Filename is " + fileName, "Ok", null);
try {
OutputStream os = FileSystemStorage.getInstance().openOutputStream(fileName);
if (os != null) {
String testOutput = "I am a test";
Dialog.show("TEST", "outstream open", "Ok", null);
os.write(testOutput.getBytes());
Dialog.show("TEST", "Written", "Ok", null);
os.close();
InputStream is = FileSystemStorage.getInstance().openInputStream(fileName);
if (is != null) {
Dialog.show("TEST", "In stream open", "Ok", null);
Dialog.show("TEST", "Bytes available : " + is.available(), "Ok", null);
byte[] dataIn = new byte[is.available()];
is.read(dataIn);
Dialog.show("TEST", "Read", "Ok", null);
        String rec = new String(dataIn);
Dialog.show("TEST", "Received " + rec, "Ok", null);
is.close();
}
}
}
catch (Exception e){
Dialog.show("TEST", "Exe " + e.getMessage(), "Ok", null);
}

mcell...@gmail.com

unread,
Feb 13, 2017, 9:11:15 AM2/13/17
to CodenameOne Discussions, mcell...@gmail.com
Hi again,

On further testing it appears that the available() method on the InputStream was returning zero.

Thanks,

Paul

Shai Almog

unread,
Feb 14, 2017, 12:33:36 AM2/14/17
to CodenameOne Discussions, mcell...@gmail.com
Hi,
available() isn't guaranteed to return anything other than 0 as this information isn't always available.
Streams are implemented very differently in C# and we go thru serious hoops to make them feel like input streams...

mcell...@gmail.com

unread,
Feb 14, 2017, 4:30:01 AM2/14/17
to CodenameOne Discussions, mcell...@gmail.com
Hi - yeah, no problem at all. 

It's just I had code that was running fine on other platforms and emulator and it takes a lot of effort to trace where the problem is coming from.

I've discovered now where the files are created when you run a UWP app on a PC and can now see the codename one generated log file. Which helps a lot - though obviously it's still not a great substitute for hardware debugging.

Thanks,

Paul

Shai Almog

unread,
Feb 15, 2017, 1:11:22 AM2/15/17
to CodenameOne Discussions, mcell...@gmail.com
Hi,
on-device-debugging is our next big target.
Reply all
Reply to author
Forward
0 new messages