FileOutputStream: Class providing an output stream of bytes to a file

Description Usage Arguments Fields and Methods Author(s) Examples

Description

Package: R.io
Class FileOutputStream

Object
~~|
~~+--OutputStream
~~~~~~~|
~~~~~~~+--FileOutputStream

Directly known subclasses:

public static class FileOutputStream
extends OutputStream

Class providing an output stream of bytes to a file.

Usage

1

Arguments

file

A File object or a filename specifying which file to write to.

Fields and Methods

Methods:

close Flushes and closes the file output stream.
finalize Finalizes the stream by first closing it.
write Writes one or more bytes to the file output stream.

Methods inherited from OutputStream:
close, finalize, flush, write

Methods inherited from Object:
$, $<-, [[, [[<-, as.character, attach, attachLocally, clearCache, clone, detach, equals, extend, finalize, gc, getEnvironment, getFields, getInstanciationTime, getStaticInstance, hasField, hashCode, ll, load, objectSize, print, save

Author(s)

Henrik Bengtsson (http://www.braju.com/R/)

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
file <- File$createTempFile("file")

fout <- FileOutputStream(file)

# Writes the bytes 0,1,2,...,255,0,1 to the temporary file
bfr <- 0:257
write(fout, bfr)

close(fout)
cat("Wrote the bytes to ", getPath(file), ".\n", sep="")

cat("Length of the file is ", size(file), " bytes.\n", sep="")

cat("Reading the bytes from ", getPath(file), ".\n", sep="")
fin <- FileInputStream(file)
while((bfr <- read(fin, len=4096))[1] != -1)
  cat(formatC(bfr, width=3))
cat("\n")

close(fin)

# Deletes the temporary file
erase(file)

HenrikBengtsson/R.io documentation built on May 6, 2019, 11:54 p.m.