You should use the fileID variable, as that is the handle to your file. You didn't define test1.txt as a variable of class, so Matlab doesn't know what you mean. So assuming no other bugs, this code should work:
filename = 'test1.txt';
delimiterIn = ',';
A = importdata(filename,delimiterIn);
fileID = fopen('test1.txt', 'r');
formatSpec = '%d %d %d %d';
sizeA = [4 Inf];
A = fscanf(fileID,formatSpec,Inf)
fclose(fileID);
A = A'