java - How to change a file reader to a directory scanner? -
answer
system.out.print("enter name of directory:"); file a= new file((new bufferedreader(new inputstreamreader(system.in))) .readline()); file[] b=a.listfiles(); for(int i=1;i < b.length;i++){ fn=b[i].getpath(); }
problem
system.out.print("enter name of file: "); fn = (new bufferedreader(new inputstreamreader(system.in))) .readline();
i have tried
file[] file array=new file(system.in).listfiles(); for(file f: filearray) // loop through files { if(f.getname().endswith(".fasta")){ fn = (new bufferedreader(new inputstreamreader(filearray)).readline()); // read files }}`
but receive error of constructor file(inputstream) undefined
i want change fn directory. how iterate through directory keeping buffered reader , inputstreamreader?
i can see want read content file...
the following classes used writing/reading data files. fileoutputstream,fileinputstream;
as can see, fileouputstream used in writing data file , fileinputstream used in reading data file.
the data can text,image,video, etc.
you can create instance of fileinputstream this
//replace string actual file name file filetoreadfrom = new file("path/to/file"); fileinputstream = new fileinputstream(filetoreadfrom);
and create instance of fileoutputstream this:
//replace string actual file name file filetowriteto= new file("path/to/file"); fileinputstream = new fileinputstream(filetowriteto);
with instances of these classes can read , write from/to file. can read more them here
Comments
Post a Comment