Thanks Josh, now it is working. Before I did not create the filereader explicitly, but just close it directly after each file reading. BR, Long
On 1/8/13, Josh Milthorpe <josh.miltho...@anu.edu.au> wrote: > Hi Long, > > I assume you are using Native X10 (x10c++). The File IO error handling > is quite basic and reports any error on calling fopen as > 'FileNotFoundException' - even if the problem is e.g. too many open file > descriptors. > > The File.lines() method silently creates a FileReader and uses it to > open and read the file. However, if you do not explicitly close the > reader, the fd will remain open until whenever the FileReader is garbage > collected (at some arbitrary future time). Therefore the net result of > your code is to open file descriptors until the system limit is reached > and fopen crashes with EMFILE. > > To fix this, try: > > var file_list:ArrayList[String]=new ArrayList[String](); > for( f1 in (0..1000)){ > for(f2 in (0..30)){ > val f_name=f1.toString()+"_"+f2.toString(); > val file=new File(f_name); > if(file.exists()) { > val reader = file.openRead(); > //Console.OUT.println(f1+"_"+f2); > for(s in reader.lines()){ > file_list.add(s); > } > reader.close(); > } > } > } > > Cheers, > > Josh > > On 08/01/13 11:01, Long Cheng wrote: >> Dear all, >> >> I tried to read a large number of files into an ArrayList with the >> following code: >> >> var file_list:ArrayList[String]=new ArrayList[String](); >> for( f1 in (0..1000)){ >> for(f2 in (0..30)){ >> val f_name=f1.toString()+"_"+f2.toString(); >> val file=new File(f_name); >> if(file.exists()) { >> //Console.OUT.println(f1+"_"+f2); >> for(s in file.lines()){ >> file_list.add(s); >> } >> } >> } >> } >> >> But in the implementations I always meet the error: >> >> Uncaught exception at place 0: x10.lang.MultipleExceptions >> x10.io.FileNotFoundException: 50_22 >> at x10::lang::CheckedThrowable::fillInStackTrace() >> at x10aux::throwException(x10::lang::CheckedThrowable*) >> at >> x10::io::FileReader__FileInputStream::_constructor(x10::lang::String*) >> at >> x10::io::FileReader__FileInputStream::_make(x10::lang::String*) >> at x10::io::FileReader::_constructor(x10::io::File*) >> at x10::io::FileReader::_make(x10::io::File*) >> at x10::io::File::openRead() >> at x10::io::File::lines() >> at active_read::main(x10::array::Array<x10::lang::String*>*) >> at x10aux::BootStrapClosure::__apply() >> at x10::lang::VoidFun_0_0::__apply(x10::lang::VoidFun_0_0*) >> at x10::lang::Activity::run() >> at x10::lang::Runtime__Worker::loop() >> at x10::lang::Runtime__Worker::__apply() >> at x10::lang::Runtime__Pool::__apply(int) >> at x10::lang::Runtime::start(x10::lang::VoidFun_0_0*) >> at >> at GC_inner_start_routine >> at GC_call_with_stack_base >> at >> at clone >> >> Actually the file 50_22 exists. I tried to initialized the size of the >> arraylist with a number large enough, and close the filereader after >> reading each file as well, but still meet the same error. Is there any >> comment about this? >> >> Thanks, >> >> Long >> >> ------------------------------------------------------------------------------ >> Master SQL Server Development, Administration, T-SQL, SSAS, SSIS, SSRS >> and more. Get SQL Server skills now (including 2012) with LearnDevNow - >> 200+ hours of step-by-step video tutorials by Microsoft MVPs and experts. >> SALE $99.99 this month only - learn more at: >> http://p.sf.net/sfu/learnmore_122512 >> _______________________________________________ >> X10-users mailing list >> X10-users@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/x10-users > > > ------------------------------------------------------------------------------ > Master SQL Server Development, Administration, T-SQL, SSAS, SSIS, SSRS > and more. Get SQL Server skills now (including 2012) with LearnDevNow - > 200+ hours of step-by-step video tutorials by Microsoft MVPs and experts. > SALE $99.99 this month only - learn more at: > http://p.sf.net/sfu/learnmore_122512 > _______________________________________________ > X10-users mailing list > X10-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/x10-users > ------------------------------------------------------------------------------ Master SQL Server Development, Administration, T-SQL, SSAS, SSIS, SSRS and more. Get SQL Server skills now (including 2012) with LearnDevNow - 200+ hours of step-by-step video tutorials by Microsoft MVPs and experts. SALE $99.99 this month only - learn more at: http://p.sf.net/sfu/learnmore_122512 _______________________________________________ X10-users mailing list X10-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/x10-users