J.File

opaque type File

J.File is an opaque value, backed by java.io.File

J.File does not have direct constructors. To create File one needs to start with J.Path

Source
__.scala

Def

inline def copy(inline p: J.Path, inline overwrite: Boolean, inline copyAttr: Boolean): J.File

Copy to new location

Copy to new location

Copies this file to new location

Returns new File

 val p: J.Path = ~~("C:", "Temp", "Test.txt")

 val f1: J.File = p.fileMake.^(_.writeString("Foo"))

 val f2: J.File = f1.copy(p.parent + "Test2.txt")

 f2 tp            // Prints: C:\Temp\Test2.txt

 f2.readString tp // Prints: Foo
Source
__.scala
inline def delete: Boolean

Delete file

Delete file

Deletes file

Source
__.scala
inline def exists: Boolean

Check if exists

Check if exists

Usually returns true, unless was deleted just before

Source
__.scala
inline def extension: String

File extension

File extension

Returns the part of file name after last period

If no period in file name, empty String is returned

  val p = J.Path("C:", "Temp", "Test.txt")

  val f: J.File = p.fileMake

  f.path tp       // Prints: C:\Temp\Test.txt

  f.name tp       // Prints: Test.txt

  f.extension tp  // Prints: txt
Source
__.scala
inline def lastModified: Time

Last updated time

Last updated time

Returns Time when this was last modified

Source
__.scala
inline def move(inline trgt: J.Path, inline overwrite: Boolean): J.File

Move file

Move file

Returns new File

 val p = J.Path("C:", "Temp", "Test.txt")

 val f1: J.File = p.fileMake.^(_.writeString("Foo"))

 val f2: J.File = f1.move(p.parent + "Test2.txt")

 f2 tp            // Prints: C:\Temp\Test2.txt

 f2.readString tp // Prints: Foo
Source
__.scala
inline def name: String

Name

Name

Last name without prior path $example

Source
__.scala
inline def openInput: J.Input

Create input

Create input

Opens J.Input to this file

Source
__.scala
inline def openOutput: J.Output

Create output

Create output

Opens J.Output to this file

Source
__.scala
inline def path: J.Path

Path

Path

Returns J.Path to this $example

Source
__.scala
inline def readString: String

Read as String

Read as String

Reads this file as String

Full code = openInput.asText.readAllAndClose

Source
__.scala
inline def real: java.io.File

Real value

Real value

Returns real value standing behind the opaque type

Inherited from
_methods
Source
Type.scala
inline def size: ByteCount

File size

File size

Returns file ByteCount

  val p = J.Path("C:", "Temp", "Test.txt")

  val f: J.File = p.fileMake

  f.writeString("ABC" * 1000)

  f.size tp // Prints: 3.0kB
Source
__.scala
inline def temp: J.File

Creates temporary file

Creates temporary file

Creates new temporary file with this file as base

if App.^.TempPath? is available, this will be the directory, otherwise this file directory will be used

Temporary file name will be `this.name' plus '.temp' or '.temp1' or '.temp2' or '.temp3' or etc. if exists

 val p = J.Path("C:", "Temp", "Test.txt")

 val f: J.File = p.fileMake

 f.temp tp // Prints: C:\Temp\Test.txt.temp

 f.temp tp // Prints: C:\Temp\Test.txt.temp1

 f.temp tp // Prints: C:\Temp\Test.txt.temp2
Source
__.scala
inline def writeString(inline s: String): Unit

Write String

Write String

Writes String to this file, overwriting prior data

Full code =

 if (exists) delete;
 openOutput.asText.writeAllAndClose(s)
Source
__.scala

Implicit

implicit inline def implicitFromJava(inline v: java.io.File): J.File
Source
__.scala