You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/reference/stdlib-types.md
+31-72Lines changed: 31 additions & 72 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -509,30 +509,32 @@ The following operations are supported for paths:
509
509
`<< : (Path, String)`
510
510
: Appends text to a file without replacing existing content. Equivalent to `append()`.
511
511
512
-
<h3>Getting attributes</h3>
512
+
<h3>Filesystem attributes</h3>
513
513
514
-
The following methods are useful for getting attributes of a path:
514
+
The following properties are available:
515
515
516
-
`exists() -> Boolean`
517
-
: Returns `true` if the path exists.
516
+
`baseName: String`
517
+
: The path name without its extension, e.g. `/some/path/file.tar.gz` -> `file.tar`.
518
518
519
-
`getBaseName() -> String`
520
-
: Gets the path name without its extension, e.g. `/some/path/file.tar.gz` -> `file.tar`.
519
+
`extension: String`
520
+
: The path extension, e.g. `/some/path/file.txt` -> `txt`.
521
521
522
-
`getExtension() -> String`
523
-
: Gets the path extension, e.g. `/some/path/file.txt` -> `txt`.
522
+
`name: String`
523
+
: The path name, e.g. `/some/path/file.txt` -> `file.txt`.
524
524
525
-
`getName() -> String`
526
-
: Gets the path name, e.g. `/some/path/file.txt` -> `file.txt`.
525
+
`parent: Path`
526
+
: The path parent path, e.g. `/some/path/file.txt` -> `/some/path`.
527
527
528
-
`getSimpleName() -> String`
529
-
: Gets the path name without any extension, e.g. `/some/path/file.tar.gz` -> `file`.
528
+
`scheme: String`
529
+
: The path URI scheme, e.g. `s3://some-bucket/hello.txt` -> `s3`.
530
530
531
-
`getParent() -> Path`
532
-
: Gets the path parent path, e.g. `/some/path/file.txt` -> `/some/path`.
531
+
`simpleName: String`
532
+
: The path name without any extension, e.g. `/some/path/file.tar.gz` -> `file`.
533
533
534
-
`getScheme() -> String`
535
-
: Gets the path URI scheme, e.g. `s3://some-bucket/hello.txt` -> `s3`.
534
+
The following methods are available for getting filesystem attributes:
535
+
536
+
`exists() -> Boolean`
537
+
: Returns `true` if the path exists.
536
538
537
539
`isDirectory() -> Boolean`
538
540
: Returns `true` if the path is a directory.
@@ -578,32 +580,17 @@ The following methods are useful for getting attributes of a path:
578
580
579
581
The following methods are available for reading files:
580
582
581
-
`eachByte( action: (byte) -> () )`
582
-
: Iterates over the file, applying the specified closure to each byte.
583
-
584
583
`eachLine( action: (String) -> () )`
585
584
: Iterates over the file, applying the specified closure to each line.
586
585
587
-
`getBytes() -> byte[]`
588
-
: Returns the file content as a byte array.
589
-
590
586
`getText() -> String`
591
587
: Returns the file content as a string.
592
588
593
-
`newInputStream() -> InputStream`
594
-
: Returns an [InputStream](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/io/InputStream.html) object to read a binary file.
595
-
596
-
`newReader() -> Reader`
597
-
: Returns a [Reader](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/io/Reader.html) object to read a text file.
598
-
599
589
`readLines() -> List<String>`
600
590
: Reads the file line by line and returns the content as a list of strings.
601
591
602
-
`withInputStream( action: (InputStream) -> () )`
603
-
: Opens a file for reading and lets you access it with an [InputStream](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/io/InputStream.html) object.
604
-
605
-
`withReader( action: (Reader) -> () )`
606
-
: Opens a file for reading and lets you access it with a [Reader](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/io/Reader.html) object.
592
+
`withReader( action: (BufferedReader) -> () )`
593
+
: Invokes the given closure with a [BufferedReader](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/io/BufferedReader.html), which can be used to read the file one line at a time using the `readLine()` method.
607
594
608
595
<h3>Writing</h3>
609
596
@@ -612,30 +599,9 @@ The following methods are available for writing to files:
612
599
`append( text: String )`
613
600
: Appends text to a file without replacing existing content.
614
601
615
-
`newOutputStream() -> OutputStream`
616
-
: Creates an [OutputStream](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/io/OutputStream.html) object that allows you to write binary data to a file.
617
-
618
-
`newPrintWriter() -> PrintWriter`
619
-
: Creates a [PrintWriter](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/io/PrintWriter.html) object that allows you to write formatted text to a file.
620
-
621
-
`newWriter() -> Writer`
622
-
: Creates a [Writer](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/io/Writer.html) object that allows you to save text data to a file.
623
-
624
-
`setBytes( bytes: byte[] )`
625
-
: Writes a byte array to a file. Equivalent to setting the `bytes` property.
626
-
627
602
`setText( text: String )`
628
603
: Writes text to a file. Equivalent to setting the `text` property.
: Applies the specified closure to an [OutputStream](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/io/OutputStream.html) object, closing it when finished.
632
-
633
-
`withPrintWriter( action: (PrintWriter) -> () )`
634
-
: Applies the specified closure to a [PrintWriter](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/io/PrintWriter.html) object, closing it when finished.
635
-
636
-
`withWriter( action: (Writer) -> () )`
637
-
: Applies the specified closure to a [Writer](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/io/Writer.html) object, closing it when finished.
638
-
639
605
`write( text: String )`
640
606
: Writes a string to a file, replacing any existing content.
641
607
@@ -691,12 +657,6 @@ The following methods are available for manipulating files and directories in a
691
657
`getPermissions() -> String`
692
658
: Returns a file's permissions using the [symbolic notation](http://en.wikipedia.org/wiki/File_system_permissions#Symbolic_notation), e.g. `'rw-rw-r--'`.
693
659
694
-
`list() -> List<String>`
695
-
: Returns the first-level elements (files and directories) of a directory as a list of strings.
696
-
697
-
`listFiles() -> List<Path>`
698
-
: Returns the first-level elements (files and directories) of a directory as a list of Paths.
699
-
700
660
`mkdir() -> Boolean`
701
661
: Creates a directory at the given path, returning `true` if the directory is created successfully, and `false` otherwise:
702
662
@@ -759,24 +719,23 @@ The following methods are available for manipulating files and directories in a
759
719
760
720
The following methods are available for listing and traversing directories:
0 commit comments