How do I open a file from disk, in a Flutter app? - dart

In a Flutter app I have a dart file located at FlutterTest\sandbox\lib\my_widget\my_widget.dart.
And I have an image located at FlutterTest\sandbox\lib\my_widget\imgs\myImage.png.
From my_widget.dart how can I point a file to this image, something along the lines of new File("???\my_widget\myImage.png")?
Just to clarify, in Java I could do something like MyClass.class.getResource("myImage.png").toString().
By the way if I print(Directory.current.path) it gives me simply /. And if I try to list the contents of this directory it tells me: "Directory listing failed, path = '/' (OS Error: Permission denied, errno = 13)". So I don't actually know where the current directory is.

You can directly access the file system but due to differences in android and iOS you'll probably end up using the path provider plugin. Also, see this flutter cookbook as they call it.
But if all you're trying to do is access a file from your build, you'll want to define it as an asset in your pubspec, and then access it using Flutter's AssetBundle (or Image.asset) rather than directly using File or Image.file. See the flutter documentation on assets.

Related

How to get absolute path to app in Electron app

I use Electron to build my app.
I want to load data from zip unpack it to folder file and show it to user.
I decompress data and then open window since its html it should work fine.
However i see that app.getAppPath() on dev mode is giving me example path D:\elektron but when i build up path is different D:elektron\resources\app how to solve this ?

Unable to render image uploaded within Electron app, built with electron-forge

I have a file uploader for users to store images, which I'm saving content to a folder within the application data directory (app.getPath('userData')). This all works fine.
When I attempt to load the image using a basic image tag, with the src pointing to the correct location within the application data directory, it fails to render.
This only occurs after I've packaged the app using electron-forge (make & package). I've only attempted to make for OS-X (darwin x-64). I'm guessing it has something to do with asar, but I can't seem to get this working. I've attempted to use the file protocol for the image source too.
Any idea how to correctly do this?
I found the easiest way is to serve all content up from a server bound to localhost

Firefox Addon SDK - How to get a list of files in a directory, and get a file

I am using the SDK to build a Firefox addon. In the addon options, the user can specify a directory of images for my addon to use (these will be added to a webpage).
I cannot figure out how to obtain a list of the files in the directory the user specified (Note that I know how to get this directory using simple-prefs). I also need to know how to get a specific file.
The file I get will be sent to a contentScriptFile to add to a webpage (as a background-image) using pageMod, via worker.port.emit(...).
So my question: How do I obtain a list of files in a directory, and how to get one of those files to send to a contentScriptFile?
I have found out how to do it, using the Low-Level API io/file
After you require() it using var fileIO = require("sdk/io/file"); you can do the following:
List files and directories in a directory using fileIO.list(path), where path is the path to the directory
Read a file using fileIO.read(path), this returns a string with the contents of the file

NULL when using fopen with xcode

I am trying to initialize a multidimensional array from a file using C for a iPhone 4inch app but I can't open up the file using fopen.
Whenever I try this I get a NULL:
FILE *f;
f=fopen("/level1.rez", "r");
if (f == NULL)
{
printf("Error Reading File\n");
//exit (0);
}
I am not sure how to open files using C.
I tried this already:
I printed out the current working directory using getcwd but all I got was "/" and when I attached that to the file name I still got NULL.
I read that if you go to product > scheme > edit scheme then options you can change the current working directory but I don't see that option.
Also I read that you can use absolute paths like: /users/name/desktop/program
but I am new to iOS development so I don't know if that is a good idea.
So how do I get fopen to work?
You CAN specify absolute paths in iOS, but the path in your example is probably used in Mac OS, which is laid out a little differently. You can specify paths to fopen() as you say, but there is more work to finding out what the first part of that path really is.
The iOS puts all AppStore apps into folders with randomly generated sandbox directory names. It is basically the the hexadecimal string of a GUID. So you need to use methods from iOS frameworks to get the first part of the path (or URL) to your file.
If the file is part of the app bundle so it can ship with the app, then you will need to use NSBundle methods to find the path to the file.
If the file is generated or downloaded after the app starts up on the device, then you need to use NSFileManager methods to determine the path to the directory of the file. (Typically the Documents directory. You can build a directory structure of your choice within the sandbox.)

test a webworks blackberry app

I have four files (config.xml, index.html, scripts.js, and styles.css). The html has a canvas and a form for users input. I want to run on blackberry simulator (Torch version 6...). I create a zip file of all those files. Then create a bin folder. Now when I run the simulator and load the application, I have either blanc screen, either the following error: Resource does not exist.
Here is the config file code:
BlackberryTest
I had the same problem. You need to use local:/// prefix before the name of the local resource to access it.

Resources