Skip to content

Commit 92c69c0

Browse files
committed
touched up filesystem guide
1 parent 5ba155a commit 92c69c0

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

sites/cheerpj/src/content/docs/11-guides/filesystem.mdx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,27 @@ title: Filesystem
33
description: Interacting with the virtual filesystem in CheerpJ
44
---
55

6-
CheerpJ provides a **virtual filesystem** that lets your Java application read and write files inside a secure, browser-sandboxed environment. For browser security reasons, it cannot access the user’s actual local disk. All file operations happen within this virtual space, which provides multiple mounting points so your application can behave much like it would on a regular filesystem.
6+
CheerpJ provides a **virtual filesystem** that allows Java applications to read and write files within a secure, browser-sandboxed environment. For browser security reasons, code running in the browser cannot access the user’s local disk directly. Instead, all file operations are confined to a virtual space, which provides multiple mounting points, each with a specific purpose and access model.
77

88
**Mounting points overview**
99

10-
- **`/app/`** — Read-only mount that points to the root of your web server. Java can read the files using the '/app/' prefix.
11-
- **`/files/`**Persistent, Java read-write area and the default mounting point for Java. JavaScript can read via CheerpJ APIs.
12-
- **`/str/`**Accessible mount used to pass data from JavaScript to Java. JavaScript can read and write, Java can only read. Not persisted.
10+
- **`/app/`** — Read-only mount that points to the root of your web server. Java can read files using the `/app/` prefix.
11+
- **`/files/`**A persistent, Java read-write area and the default mounting point for Java. JavaScript can read via CheerpJ APIs.
12+
- **`/str/`**A transient mount used to pass data from JavaScript to Java. JavaScript can read and write, Java can only read. Not persisted.
1313

14-
If a file is served by your HTTP server (e.g., alongside your JARs), your Java code can read it via the `/app` prefix. For any other local files, it is necessary to load them into the virtual filesystem first. Either `/str` (inject from JavaScript) or `/files` (read/write at runtime). CheerpJ provides several ways to move files into and out of this virtual filesystem.
14+
If a file is served by your HTTP server (e.g., alongside your JARs), your Java code can read it via the `/app` prefix. For any other local files, it is necessary to load them into the virtual filesystem first, either via `/str` (inject from JavaScript) or `/files` (read/write at runtime). CheerpJ provides several ways to move files into and out of this virtual filesystem.
1515

1616
> For a detailed overview of mounting points (`/app/`, `/files/`, `/str/`) and how they work, see the **[File and Filesystem guide](/docs/explanation/File-System-support)**.
1717
1818
## Loading Files from JavaScript into the Virtual Filesystem
1919

20-
While your application runs under **CheerpJ**, any page-provided assets must first be placed in the **virtual filesystem** for Java to access them. Expose them from JavaScript to the `/str/` mount either through [`cheerpOSAddStringFile`](/docs/reference/cheerpOSAddStringFile) or using [Library Mode](/docs/guides/implementing-native-libraries), and then read them from your Java code like regular files.
20+
While your application runs under **CheerpJ**, any page-provided assets must first be placed in the **virtual filesystem** for Java to access them. Expose them from JavaScript to the `/str/` mount using [`cheerpOSAddStringFile`](/docs/reference/cheerpOSAddStringFile) or [Library Mode](/docs/guides/implementing-native-libraries), and then read them from Java like regular files.
2121

2222
### Method 1: Using `cheerpOSAddStringFile` (string or binary).
2323

2424
The quickest way to place a file into CheerpJ’s virtual filesystem from JavaScript is `cheerpOSAddStringFile`. It’s ideal for string content and also supports binary data.
2525

26-
**When to call it:** Invoke `cheerpOSAddStringFile` after `cheerpjInit()` finishes (i.e., once its Promise resolves). The API depends on the runtime and virtual file system being fully initialized.
26+
**When to call it:** Invoke `cheerpOSAddStringFile` after `cheerpjInit()` finishes (i.e., once its Promise resolves). The API depends on the runtime and virtual filesystem being fully initialized.
2727

2828
```js
2929
// Call this only after cheerpjInit() has resolved.
@@ -54,7 +54,7 @@ System.out.println(text);
5454

5555
### Method 2: Using library mode
5656

57-
When a file already lives under `/app/` but your Java code needs to read it as if it were in `/files/` (i.e., without the `/app/` prefix), use [libraries mode](/docs/guides/library-mode) to copy it across mounts. With [`cheerpjRunLibrary`](/docs/reference/cheerpjRunLibrary), you can invoke Java’s `java.nio.file` from JavaScript to copy the file from `/app/…` to `/files/…`, after which the application can open it using just its bare filename.
57+
When a file already lives under `/app/` but your Java code needs to read it as if it were in `/files/` (i.e., without the `/app/` prefix), use [Library Mode](/docs/guides/library-mode) to copy it across mounts. With [`cheerpjRunLibrary`](/docs/reference/cheerpjRunLibrary), you can invoke Java’s `java.nio.file` from JavaScript to copy the file from `/app/…` to `/files/…`, after which the application can open it using just its bare filename.
5858

5959
```js
6060
async function copyFileToFilesMountPoint() {
@@ -88,7 +88,7 @@ copyFileToFilesMountPoint();
8888
// without needing the /app/ prefix.
8989
```
9090

91-
## Getting a file from the Virtual File System to JavaScript (i.e local file system)
91+
## Getting a file from the virtual filesystem to JavaScript (i.e. the local file system)
9292

9393
When Java runs under **CheerpJ**, files are saved to the **virtual filesystem** (default **`/files/`**), not the user’s disk. You can expose these files to the page either directly from JavaScript or by handing off from Java to JavaScript via a native method.
9494

@@ -167,7 +167,7 @@ async function Java_App_downloadFileFromCheerpJ(lib, fileName) {
167167
// Simulate a click on the link and clean up objects
168168
link.click();
169169
link.remove();
170-
URL.revokeObjectURL(url);
170+
URL.revokeObjectURL(link.href);
171171

172172
console.log(`Successfully downloaded ${fileName}`);
173173
} catch (e) {
@@ -190,7 +190,7 @@ cj3init();
190190

191191
`JFileChooser` works the same under CheerpJ, but it targets the **virtual filesystem**. By default the dialog opens in `/files/` mount (the writable, persistent area), so any file you open or save is referenced by a virtual file system path (e.g., `/files/report.txt`) rather than the user’s physical disk.
192192

193-
Here is how the dialog will look like when you use `JFileChooser` in CheerpJ with the default `/files/` mount point:
193+
Here is how the dialog looks like when you use `JFileChooser` with the default `/files/` mount point:
194194
![](/docs/cheerpj3/assets/filechooser.png)
195195

196196
You can still perform normal Java file operations with CheerpJ. The paths simply refer to the virtual filesystem rather than the user’s physical disk.

0 commit comments

Comments
 (0)