public class UtilsIO extends Object
Modifier | Constructor and Description |
---|---|
private |
UtilsIO() |
Modifier and Type | Method and Description |
---|---|
static void |
cp(File inFile,
File outFile)
Copy a file.
|
static void |
cp(InputStream in,
OutputStream out)
Copy the content of an
InputStream in an OutputStream . |
static int |
getUnsignedInt(byte b)
Convert a byte in an unsigned int.
|
static boolean |
mv(File from,
File to)
Moves a file.
|
static void |
print(InputStream in)
Write the content of the input stream on the
System.out . |
static StringBuilder |
readFromFile(File file)
Reads the content of a text file.
|
static boolean |
writeToFile(File file,
String text)
Writes a string in a text file.
|
public static StringBuilder readFromFile(File file) throws FileNotFoundException, IOException
StringBuilder
for efficency.file
- file to be readFileNotFoundException
- if the file does not existIOException
- if I/O errors occourpublic static boolean writeToFile(File file, String text)
In case of error, the writing is interrupted and a log is produced on the standard output.
file
- file to be writtentext
- text to writepublic static void cp(InputStream in, OutputStream out) throws IOException
InputStream
in an OutputStream
.
At the end of the copy, the streams are not closed.in
- stream to readout
- stream to writeIOException
- if I/O errors occourpublic static void cp(File inFile, File outFile) throws IOException
inFile
- file to be copiedoutFile
- file in which to copyFileNotFoundException
- if inFile does not existIOException
- if I/O errors occourpublic static void print(InputStream in)
System.out
.
This method is suitable if the input stream is a character stream.in
- an InputStream to readpublic static boolean mv(File from, File to) throws IOException
File.renameTo(java.io.File)
;
if this fail, a copy is made and the original file is deleted.
Note: if the original file can not be deleted, the method actually makes a copy.
from
- file to moveto
- new file positionFilenotFoundException
- if file from does not existIOException
- if I/O errors occourpublic static int getUnsignedInt(byte b)
b
- a byte© 2013 andynaz - http://andynaz.altervista.org