Clear Filters
Clear Filters

Why do I receive an error when I call the "read" method of the FileInputStream in MATLAB?

2 views (last 30 days)
When I call the "read" method of the FileInputStream in MATLAB while running the following commands:
myFile ='dummyfile.txt');
b = javaArray ('java.lang.Byte',5)
I receive the error:
??? No method read with matching signature found for class
Based on the java doc for the, the read method can take a byte[] input:
int read(byte[] b)

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 17 May 2010
This error is due to the lack of support for primitive Java data types in MATLAB. The "read" method of the FileInputStream class in the package actually expects an array of primitive bytes (byte[]) and not an array of the Byte wrapper object (java.lang.Byte[]).
As a work around, you can use the overloaded read method that does not take any input arguments within a loop:
myFile ='dummyfile.txt');
b = zeros(1,myFile.available);
for n = 1:length(b)
b(n) =;
In order to use a function such as this in this manner, you would need to declare the function as follows:
int read(java.lang.Byte[] b)

More Answers (0)


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!