public final class SimpleIO extends Object
String text = SimpleIO.with(this).readFileText(R.raw.myfile);
Modifier and Type | Method and Description |
---|---|
File |
getDocumentsDirectory()
Returns the directory where documents are stored on this device.
|
File |
getDownloadsDirectory()
Returns the directory where downloads are stored on this device.
|
File |
getMoviesDirectory()
Returns the directory where movies are stored on this device.
|
File |
getMusicDirectory()
Returns the directory where music is stored on this device.
|
File |
getPhotosDirectory()
Returns the directory where photos are stored on this device.
|
File |
getPodcastsDirectory()
Returns the directory where podcasts are stored on this device.
|
BufferedReader |
openExternalFileBufferedReader(String dir,
String filename)
Opens and returns a FileInputStream to read the given file in the given
external directory.
|
FileInputStream |
openExternalFileInputStream(String dir,
String filename)
Opens and returns a Scanner to read the given file in the given
external directory.
|
PrintStream |
openExternalFilePrintStream(String dir,
String filename)
Opens and returns a PrintStream to write the given file in the given
external directory.
|
PrintStream |
openExternalFilePrintStream(String dir,
String filename,
boolean append)
Opens and returns a PrintStream to write the given file in the given
external directory.
|
Scanner |
openExternalFileScanner(String dir,
String filename)
Opens and returns a Scanner to read the given file in the given
external directory.
|
FileInputStream |
openFileInput(File file)
Opens an external file for reading.
|
FileInputStream |
openFileInput(File directory,
String filename)
Opens an external file in the given directory for reading.
|
FileInputStream |
openFileInput(String filename)
Opens an external file for reading.
|
FileOutputStream |
openFileOutput(File file,
int mode)
Opens an external file for writing in the given mode, such as Context.MODE_PRIVATE or MODE_APPEND.
|
FileOutputStream |
openFileOutput(File directory,
String name,
int mode)
Opens an external file in the given directory for writing in the given mode,
such as Context.MODE_PRIVATE or MODE_APPEND.
|
FileOutputStream |
openFileOutput(String name,
int mode)
Opens an external file for writing in the given mode, such as Context.MODE_PRIVATE or MODE_APPEND.
|
BufferedReader |
openInternalFileBufferedReader(File file)
Opens a BufferedReader for reading from the given file.
|
BufferedReader |
openInternalFileBufferedReader(File directory,
String filename)
Opens a BufferedReader for reading from the given file in the given directory.
|
BufferedReader |
openInternalFileBufferedReader(int id)
Opens a BufferedReader to read the file with the given ID.
|
BufferedReader |
openInternalFileBufferedReader(String filename)
Opens a BufferedReader for reading from the given file.
|
PrintStream |
openInternalFilePrintStream(File file)
Opens a PrintStream for writing into the given file, replacing any previous data.
|
PrintStream |
openInternalFilePrintStream(File file,
boolean append)
Opens a PrintStream for writing into the given file.
|
PrintStream |
openInternalFilePrintStream(File directory,
String filename)
Opens a PrintStream for writing into the given file, replacing any previous data.
|
PrintStream |
openInternalFilePrintStream(File directory,
String filename,
boolean append)
Opens a PrintStream for writing into the given file.
|
PrintStream |
openInternalFilePrintStream(String filename)
Opens a PrintStream for writing into the given file, replacing any previous data.
|
PrintStream |
openInternalFilePrintStream(String filename,
boolean append)
Opens a PrintStream for writing into the given file.
|
Scanner |
openInternalFileScanner(File file)
Opens a Scanner to read the file with the given name.
|
Scanner |
openInternalFileScanner(File directory,
String filename)
Opens a Scanner to read the file with the given name.
|
Scanner |
openInternalFileScanner(int id)
Opens a Scanner to read the file with the given ID.
|
Scanner |
openInternalFileScanner(String filename)
Opens a Scanner to read the file with the given name.
|
InputStream |
openInternalFileStream(int id)
Opens an InputStream to read the file with the given ID.
|
ArrayList<String> |
readFileLines(File file)
Reads the entire text of the given file, returning it as a list of lines.
|
ArrayList<String> |
readFileLines(File directory,
String filename)
Reads the entire text of the given file, returning it as a list of lines.
|
ArrayList<String> |
readFileLines(InputStream stream)
Reads the entire text from the given stream, returning it as a list of lines.
|
ArrayList<String> |
readFileLines(int id)
Reads the entire text of the file with the given ID, returning it as a list of lines.
|
ArrayList<String> |
readFileLines(String filename)
Reads the entire text of the given file, returning it as a list of lines.
|
String |
readFileText(File file)
Reads the entire text of the given file, returning it as a string.
|
String |
readFileText(File directory,
String filename)
Reads the entire text of the given file, returning it as a string.
|
String |
readFileText(InputStream stream)
Reads the entire text from the given stream, returning it as a string.
|
String |
readFileText(int id)
Reads the entire text of the file with the given ID, returning it as a string.
|
String |
readFileText(String filename)
Reads the entire text of the given file, returning it as a string.
|
static SimpleIO |
with(Context context)
Returns a singleton SimpleIO instance bound to the given context.
|
static SimpleIO |
with(View context)
Returns a singleton SimpleIO instance bound to the given view's context.
|
SimpleIO |
writeFileLines(File file,
List<String> lines)
Writes the given list of lines into the given file, replacing any previous data.
|
SimpleIO |
writeFileLines(File file,
List<String> lines,
boolean append)
Writes the given text into the given file.
|
SimpleIO |
writeFileLines(File directory,
String filename,
List<String> lines)
Writes the given list of lines into the given file, replacing any previous data.
|
SimpleIO |
writeFileLines(File directory,
String filename,
List<String> lines,
boolean append)
Writes the given text into the given file.
|
SimpleIO |
writeFileLines(String filename,
List<String> lines)
Writes the given list of lines into the given file, replacing any previous data.
|
SimpleIO |
writeFileLines(String filename,
List<String> lines,
boolean append)
Writes the given text into the given file.
|
SimpleIO |
writeFileText(File file,
String text)
Writes the given text into the given file, replacing any previous data.
|
SimpleIO |
writeFileText(File file,
String text,
boolean append)
Writes the given text into the given file.
|
SimpleIO |
writeFileText(File directory,
String filename,
String text)
Writes the given text into the given file, replacing any previous data.
|
SimpleIO |
writeFileText(File directory,
String filename,
String text,
boolean append)
Writes the given text into the given file.
|
SimpleIO |
writeFileText(String filename,
String text)
Writes the given text into the given file, replacing any previous data.
|
SimpleIO |
writeFileText(String filename,
String text,
boolean append)
Writes the given text into the given file.
|
public static SimpleIO with(Context context)
public static SimpleIO with(View context)
public File getDocumentsDirectory()
public File getDownloadsDirectory()
public File getMoviesDirectory()
public File getMusicDirectory()
public File getPhotosDirectory()
public File getPodcastsDirectory()
public BufferedReader openExternalFileBufferedReader(String dir, String filename)
IORuntimeException
- if the file does not exist or cannot be read.public Scanner openExternalFileScanner(String dir, String filename)
IORuntimeException
- if the file does not exist or cannot be read.public PrintStream openExternalFilePrintStream(String dir, String filename)
IORuntimeException
- if the file cannot be written.public PrintStream openExternalFilePrintStream(String dir, String filename, boolean append)
IORuntimeException
- if the file cannot be written.public FileInputStream openExternalFileInputStream(String dir, String filename)
IORuntimeException
- if the file cannot be written.public FileInputStream openFileInput(File file)
IORuntimeException
- if the file does not exist or cannot be read.public FileInputStream openFileInput(File directory, String filename)
IORuntimeException
- if the file does not exist or cannot be read.public FileInputStream openFileInput(String filename)
IORuntimeException
- if the file does not exist or cannot be read.public FileOutputStream openFileOutput(File file, int mode)
IORuntimeException
- if the file does not exist or cannot be written.public FileOutputStream openFileOutput(File directory, String name, int mode)
IORuntimeException
- if the file does not exist or cannot be written.public FileOutputStream openFileOutput(String name, int mode)
IORuntimeException
- if the file does not exist or cannot be written.public BufferedReader openInternalFileBufferedReader(File file)
public BufferedReader openInternalFileBufferedReader(File directory, String filename)
public BufferedReader openInternalFileBufferedReader(String filename)
public PrintStream openInternalFilePrintStream(File file)
public PrintStream openInternalFilePrintStream(File directory, String filename)
public PrintStream openInternalFilePrintStream(String filename)
public PrintStream openInternalFilePrintStream(File file, boolean append)
public PrintStream openInternalFilePrintStream(File directory, String filename, boolean append)
public PrintStream openInternalFilePrintStream(String filename, boolean append)
public Scanner openInternalFileScanner(File file)
public Scanner openInternalFileScanner(File directory, String filename)
public Scanner openInternalFileScanner(String filename)
public BufferedReader openInternalFileBufferedReader(@RawRes int id)
public Scanner openInternalFileScanner(@RawRes int id)
public InputStream openInternalFileStream(@RawRes int id)
public ArrayList<String> readFileLines(@RawRes int id)
public ArrayList<String> readFileLines(File file)
IORuntimeException
- if the file cannot be read.public ArrayList<String> readFileLines(File directory, String filename)
IORuntimeException
- if the file cannot be read.public ArrayList<String> readFileLines(InputStream stream)
IORuntimeException
- if the file cannot be read.public ArrayList<String> readFileLines(String filename)
IORuntimeException
- if the file cannot be read.public String readFileText(@RawRes int id)
public String readFileText(File file)
IORuntimeException
- if the file cannot be read.public String readFileText(InputStream stream)
IORuntimeException
- if the file cannot be read.public String readFileText(File directory, String filename)
IORuntimeException
- if the file cannot be read.public String readFileText(String filename)
IORuntimeException
- if the file cannot be read.public SimpleIO writeFileLines(File file, List<String> lines)
public SimpleIO writeFileLines(File directory, String filename, List<String> lines)
public SimpleIO writeFileLines(String filename, List<String> lines)
public SimpleIO writeFileLines(File file, List<String> lines, boolean append)
public SimpleIO writeFileLines(File directory, String filename, List<String> lines, boolean append)
public SimpleIO writeFileLines(String filename, List<String> lines, boolean append)
public SimpleIO writeFileText(File file, String text)
public SimpleIO writeFileText(File directory, String filename, String text)
public SimpleIO writeFileText(String filename, String text)
public SimpleIO writeFileText(File file, String text, boolean append)
public SimpleIO writeFileText(File directory, String filename, String text, boolean append)