public final class IO extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static java.nio.charset.Charset |
defaultCharset()
Returns the default charset.
|
static boolean |
fileExists(java.lang.Object file)
Check if a file exists.
|
static java.lang.String |
fileToText(java.lang.Object file,
java.lang.Object encoding)
Reads the content of a text file.
|
static java.io.PrintStream |
printStreamFrom(java.lang.Object output)
Create an
PrintStream from the specified value. |
static java.io.PrintStream |
printStreamFrom(java.lang.Object output,
java.lang.Object charset)
Create an
PrintStream from the specified value. |
static java.lang.String |
readln()
Reads the next line of characters from the console.
|
static java.lang.String |
readln(java.lang.String message)
Reads the next line of characters from the console.
|
static java.lang.String |
readPassword()
Reads a password from the console with echoing disabled.
|
static java.lang.String |
readPassword(java.lang.String message)
Reads a password from the console with echoing disabled.
|
static char[] |
secureReadPassword()
Reads a password from the console with echoing disabled, returning an
char[] array. |
static char[] |
secureReadPassword(java.lang.String message)
Reads a password from the console with echoing disabled, returning an
char[] array. |
static void |
textToFile(java.lang.Object text,
java.lang.Object file)
Writes some text to a file.
|
static void |
textToFile(java.lang.Object text,
java.lang.Object file,
java.lang.Object charset)
Writes some text to a file using the given
Charset. |
static java.nio.charset.Charset |
toCharset(java.lang.Object encoding)
Convert the given String or Charset object into a Charset.
|
static java.nio.file.Path |
toPath(java.lang.Object file)
Polymorphic
Path creation. |
static java.net.URL |
toURL(java.lang.Object ref)
Polymorphic
URL creation. |
public static java.nio.charset.Charset defaultCharset()
public static java.nio.charset.Charset toCharset(java.lang.Object encoding)
public static java.lang.String fileToText(java.lang.Object file, java.lang.Object encoding) throws java.lang.Throwable
file - the file to read from as an instance of either String, File or Path.encoding - the file encoding as a String or Charset.String.java.lang.Throwablepublic static java.nio.file.Path toPath(java.lang.Object file)
Path creation.file - the file descriptor as an instance of either String, File or Path.Path object.public static java.net.URL toURL(java.lang.Object ref) throws java.net.MalformedURLException
URL creation.ref - the url descriptor as a String, URL, URI, File or Path.URL object.java.net.MalformedURLExceptionpublic static void textToFile(java.lang.Object text, java.lang.Object file) throws java.lang.Throwable
"-", the content is written to standard output.text - the text to write.file - the file to write to as an instance of either String, File or Path.java.lang.Throwablepublic static void textToFile(java.lang.Object text, java.lang.Object file, java.lang.Object charset) throws java.lang.Throwable
Charset.
The file and parents directories are created if they does not exist. The file is overwritten if it already exists. If the file is "-", the content is written to standard output.text - the text to write.file - the file to write to as an instance of either String, File or Path.charset - the charset to encode the text in.java.lang.Throwablepublic static boolean fileExists(java.lang.Object file)
file - the file to read from as an instance of either String, File or Path.public static java.lang.String readln() throws java.io.IOException
java.io.IOExceptionpublic static java.lang.String readln(java.lang.String message) throws java.io.IOException
message - displays a prompt message.java.io.IOExceptionpublic static java.lang.String readPassword() throws java.io.IOException
java.io.IOExceptionpublic static java.lang.String readPassword(java.lang.String message) throws java.io.IOException
message - displays a prompt message.java.io.IOExceptionpublic static char[] secureReadPassword() throws java.io.IOException
char[] array.java.io.IOExceptionpublic static char[] secureReadPassword(java.lang.String message) throws java.io.IOException
char[] array.message - displays a prompt message.java.io.IOExceptionpublic static java.io.PrintStream printStreamFrom(java.lang.Object output) throws java.io.IOException
PrintStream from the specified value.
Same as printStreamFrom(output, defaultCharset())
output - the file to use; "-" means standard outputPrintStream or java.lang.System.outjava.io.IOExceptiondefaultCharset(),
printStreamFrom(Object, Object)public static java.io.PrintStream printStreamFrom(java.lang.Object output, java.lang.Object charset) throws java.io.IOException
PrintStream from the specified value.
If the given string is "-", java.lang.System.out is used. Otherwise, a java.nio.file.Path is
created with toPath(Object).
The returned PrintStream is buffered and uses the given charset. Parent directory is created. If the file
exists, it is overwritten.
output - the file to use; "-" means standard outputcharset - the charset to use, as a java.lang.String or a java.nio.charset.CharsetPrintStream or java.lang.System.outjava.io.IOExceptiontoPath(Object),
toCharset(Object)