Java Utililty Methods File Save

List of utility methods to do File Save

Description

The list of methods to do File Save are organized into topic(s).

Method

voidsave(InputStream is, OutputStream os)
save
byte[] inbuf = new byte[1024];
do {
    int nCount = is.read(inbuf);
    if (nCount > 0) {
        os.write(inbuf, 0, nCount);
} while (is.available() > 0);
voidsave(OutputStream out, InputStream iStream)
Guarda en un stream de escritura lo contenido en un stream de lectura
try {
    byte[] buffer = new byte[1024];
    int len;
    while ((len = iStream.read(buffer)) > -1) {
        out.write(buffer, 0, len);
} catch (IOException e) {
    System.out.println("Error guardando en stream de escritura" + e.getMessage());
...
voidsaveBytesAsIfile(final IFile file, final byte[] bytes)
Helper to write an ifile to the workspace from a string.
file.setContents(new ByteArrayInputStream(bytes),  true,  false,
         null);
voidsaveContent(OutputStream os, byte[] content)
Saves the content in the output stream
BufferedOutputStream bos = new BufferedOutputStream(os);
bos.write(content);
bos.close();
StringsaveConvert(String theString, boolean escapeSpace)
save Convert
if (theString == null) {
    return ""; 
int len = theString.length();
StringBuffer outBuffer = new StringBuffer(len * 2);
for (int x = 0; x < len; x++) {
    char aChar = theString.charAt(x);
    switch (aChar) {
...
voidsaveDoubleMatrix(double[][] matrix, PrintStream out)
save Double Matrix
int rows = matrix.length;
int cols = matrix[0].length;
out.println(rows + " " + cols);
for (int i = 0; i < rows; i++) {
    for (int j = 0; j < cols; j++) {
        out.print(matrix[i][j]);
        if (j != cols - 1) {
            out.print(" ");
...
FilesaveFile(InputStream st, File testFile)
save File
BufferedReader r = new BufferedReader(new InputStreamReader(st));
String line;
try (PrintStream wr = new PrintStream(testFile)) {
    while ((line = r.readLine()) != null) {
        wr.println(line);
return testFile;
...
voidsaveFile(String fname, byte[] bytes)
save File
File file = new File(fname);
if (file.exists()) {
    file.delete();
RandomAccessFile raf = new RandomAccessFile(file, "rw");
raf.seek(0L);
raf.setLength(0L);
raf.write(bytes);
...
FilesaveFile(String where)
Identical to savePath(), but returns a File object.
return new File(savePath(where));
booleansaveInputToOutput(InputStream is, OutputStream os)
Save stream from input to output.
byte[] buffer = new byte[1024];
int i = -1;
while ((i = is.read(buffer)) != -1) {
    os.write(buffer, 0, i);
os.flush();
return true;