
- Java.io - Home
- Java.io - BufferedInputStream
- Java.io - BufferedOutputStream
- Java.io - BufferedReader
- Java.io - BufferedWriter
- Java.io - ByteArrayInputStream
- Java.io - ByteArrayOutputStream
- Java.io - CharArrayReader
- Java.io - CharArrayWriter
- Java.io - Console
- Java.io - DataInputStream
- Java.io - DataOutputStream
- Java.io - File
- Java.io - FileDescriptor
- Java.io - FileInputStream
- Java.io - FileOutputStream
- Java.io - FilePermission
- Java.io - FileReader
- Java.io - FileWriter
- Java.io - FilterInputStream
- Java.io - FilterOutputStream
- Java.io - FilterReader
- Java.io - FilterWriter
- Java.io - InputStream
- Java.io - InputStreamReader
- Java.io - LineNumberInputStream
- Java.io - LineNumberReader
- Java.io - ObjectInputStream
- Java.io - ObjectInputStream.GetField
- Java.io - ObjectOutputStream
- io - ObjectOutputStream.PutField
- Java.io - ObjectStreamClass
- Java.io - ObjectStreamField
- Java.io - OutputStream
- Java.io - OutputStreamWriter
- Java.io - PipedInputStream
- Java.io - PipedOutputStream
- Java.io - PipedReader
- Java.io - PipedWriter
- Java.io - PrintStream
- Java.io - PrintWriter
- Java.io - PushbackInputStream
- Java.io - PushbackReader
- Java.io - RandomAccessFile
- Java.io - Reader
- Java.io - SequenceInputStream
- Java.io - SerializablePermission
- Java.io - StreamTokenizer
- Java.io - StringBufferInputStream
- Java.io - StringReader
- Java.io - StringWriter
- Java.io - Writer
- Java.io package Useful Resources
- Java.io - Discussion
Java - FilterReader markSupported() method
Description
The Java FilterReader markSupported() method marks the present position of the stream.
Declaration
Following is the declaration for java.io.FilterReader.markSupported() method −
public void markSupported()
Parameters
NA
Return Value
This method returns true if this stream support the mark operation.
Exception
NA
Example - Usage of FilterReader markSupported() method
The following example shows the usage of Java FilterReader markSupported() method.
FilterReaderDemo.java
package com.tutorialspoint; import java.io.FilterReader; import java.io.Reader; import java.io.StringReader; public class FilterReaderDemo { public static void main(String[] args) throws Exception { FilterReader fr = null; Reader r = null; boolean bool = false; try { // create new reader r = new StringReader("ABCDEF"); // create new filter reader fr = new FilterReader(r) { }; // tests if the filter reader supports mark() bool = fr.markSupported(); // prints System.out.print("If mark() supported? "+bool); } catch(Exception e) { // if any I/O error occurs e.printStackTrace(); } finally { // releases system resources associated with this stream if(r!=null) r.close(); if(fr!=null) fr.close(); } } }
Output
Let us compile and run the above program, this will produce the following result−
If mark() supported? true
Example - Writing a String as Bytes to a File
The following example shows the usage of Java FilterReader markSupported() method.
FilterReaderDemo.java
package com.tutorialspoint; import java.io.FileOutputStream; import java.io.IOException; public class FilterReaderDemo { public static void main(String[] args) { String data = "Hello, FileOutputStream!"; try (FileOutputStream fos = new FileOutputStream("output.txt")) { // Convert string to byte array byte[] byteData = data.getBytes(); // Write byte array to the file fos.write(byteData); System.out.println("Data written successfully to output.txt."); } catch (IOException e) { e.printStackTrace(); } } }
Output
Let us compile and run the above program, this will produce the following result−
Data written successfully to output.txt.
Explanation
Converts a string into a byte array using .getBytes().
Creates a FileOutputStream for "output.txt".
Writes the byte array to the file.
The file will be overwritten if it already exists.
Example - Writing Binary Data (Image or File Content)
The following example shows the usage of Java FilterReader markSupported() method.
FilterReaderDemo.java
package com.tutorialspoint; import java.io.FileOutputStream; import java.io.IOException; public class FilterReaderDemo { public static void main(String[] args) { byte[] binaryData = {65, 66, 67, 68, 69}; // ASCII values of 'A', 'B', 'C', 'D', 'E' try (FileOutputStream fos = new FileOutputStream("binary_output.bin")) { // Writing byte array to the file fos.write(binaryData); System.out.println("Binary data written to binary_output.bin."); } catch (IOException e) { e.printStackTrace(); } } }
Output
Let us compile and run the above program, this will produce the following result−
Binary data written to binary_output.bin.
Explanation
Creates a byte array {65, 66, 67, 68, 69}, which corresponds to "ABCDE".
Creates a FileOutputStream for "binary_output.bin".
Writes the byte array to the file.
The file stores raw binary data instead of text.