diff options
Diffstat (limited to 'src/main/scala/forge/ReadWrite.scala')
-rw-r--r-- | src/main/scala/forge/ReadWrite.scala | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/main/scala/forge/ReadWrite.scala b/src/main/scala/forge/ReadWrite.scala new file mode 100644 index 00000000..ee74f35f --- /dev/null +++ b/src/main/scala/forge/ReadWrite.scala @@ -0,0 +1,20 @@ +package forge +import java.nio.{file => jnio} + +trait ReadWrite[T] { + def write(t: T, p: jnio.Path): Unit + def read(p: jnio.Path): T +} + +object ReadWrite{ + implicit object String extends ReadWrite[java.lang.String]{ + def write(t: String, p: jnio.Path) = { + jnio.Files.createDirectories(p.getParent) + jnio.Files.deleteIfExists(p) + jnio.Files.write(p, t.getBytes) + } + def read(p: jnio.Path) = { + new String(jnio.Files.readAllBytes(p)) + } + } +} |