Name |
Ceylon File Platform Module |
---|---|
Description |
API for accessing hierarchical file systems. Clients use
value path = parsePath("/Users/Trompon/Documents"); value child = path.childPath("hello.txt"); value sibling = child.siblingPath("goodbye.txt"); value parent = path.parent; The attribute resource of
To create a file named value filePath = home.childPath("hello.txt"); if (is Nil loc = filePath.resource) { value file = loc.createFile(); try (writer = file.Overwriter()) { writer.writeLine("Hello, World!"); } } else { print("file already exists"); } Note the difference between a To print the contents of the file we just created, we could do this: value filePath = home.childPath("hello.txt"); if (is File file = filePath.resource) { try (reader = file.Reader()) { print(reader.readLine()); } } else { print("file does not exist"); } Now, to rename the file: value filePath = home.childPath("hello.txt"); if (is File file = filePath.resource) { value newPath = filePath.siblingPath("goodbye.txt"); if (is Nil loc = newPath.resource) { file.move(loc); } else { print("target file already exists"); } } else { print("source file does not exist"); } To list the contents of a directory, we have two possibilities. We can list just the direct contents: if (is Directory dir = home.resource) { for (path in dir.childPaths()) { print(path); } } else { print("directory does not exist"); } Alternatively, we can create a object visitor extends Visitor() { file(File file) => print(file.path); } home.visit(visitor); File systems other than the default file system are
supported. For example, a file system for a zip file may be
created using the convenience function value zipPath = home.childPath("myzip.zip"); if (is Nil|File loc = zipPath.resource) { value zipSystem = createZipFileSystem(loc); value entryPath = zipSystem.parsePath("/hello.txt"); if (is Nil entry = entryPath.resource) { value filePath = home.childPath("hello.txt"); if (is File file = filePath.resource) { file.copy(entry); } else { print("source file does not exist"); } } else { print("entry already exists"); } zipSystem.close(); } |
Category |
SDK
The Ceylon SDK |
Last Published | Aug 21, 2017 |
Stats |
Downloads (JVM): 48578 Downloads (JS): 0 Source downloads: 14360 |
Module links |
Home Code repository Issue tracker Imported By Browse |
1.3.3 | JVM JVM: 1.2.x, 1.3.x (latest) | Published Aug 21, 2017 |
Browse |
View docs |
|
1.3.2 | JVM JVM: 1.2.x, 1.3.x (latest) | Published Mar 1, 2017 |
Browse |
View docs |
|
1.3.1 | JVM JVM: 1.2.x, 1.3.x (latest) | Published Nov 21, 2016 |
Browse |
View docs |
|
1.3.0 | JVM JVM: 1.2.x, 1.3.x (latest) | Published Sep 15, 2016 |
Browse |
View docs |
|
1.2.2 | JVM JVM: 1.2.x, 1.3.x (latest) | Published Mar 11, 2016 |
Browse |
View docs |
|
1.2.1 | JVM JVM: 1.2.x, 1.3.x (latest) | Published Feb 11, 2016 |
Browse |
View docs |
|
1.2.0 | JVM JVM: 1.2.x, 1.3.x (latest) | Published Oct 28, 2015 |
Browse |
View docs |
|
1.1.0 | JVM JVM: 1.1.0 (outdated) | Published Oct 8, 2014 |
Browse |
View docs |
|
1.0.0 | JVM JVM: 1.0.0 (outdated) | Published Nov 11, 2013 |
Browse |
View docs |
|
0.6.1 | JVM JVM: M6 (outdated) | Published Sep 24, 2013 |
Browse |
View docs |
|
0.6 | JVM JVM: M6 (outdated) | Published Sep 20, 2013 |
Browse |
View docs |
|
0.5 | JVM JVM: M5 (outdated) | Published Mar 14, 2013 |
Browse |
View docs |
|
0.4 | JVM JVM: M4 (oudated) | Published Oct 29, 2012 |
Browse |
View docs |
|
0.3.2 | JVM JVM: M3.1 (outdated) | Published Jul 6, 2012 |
Browse |
View docs |
|
0.3.1 | JVM JVM: M3 (outdated) | Published Jun 22, 2012 |
Browse |
View docs |
|
0.3 | JVM JVM: M2 (outdated) | Published Jun 8, 2012 |
Browse |
View docs |