For levantiep and rgholami (and others who come along later),
In levantiep's case it is most likely that you are trying to 'read' a file which doesn't really exist. Since you are testing in the simulator I'd try first to read a file off of the SDCard since you can easily verify if the file exists in the simulator directory or not (sorry, I haven't figured out where the simulator keeps files which are on the device memory - possibly someone else can tell us this info). When the simulator starts up you need to tell it where to put the SDCard files by selecting 'Simulte' -> 'Change SD Card'. By default it is set to 'None' - you need to choose a directory and the default directory is usually the directory where you installed the simulator. In that directory the simulator will create a directory call Blackberry with all of the subdirectories needed (such as
audiobooks, documents, music, pictures etc.). Once you do this a message will pop up in the simulater saying the SD Card is inserted (note that you must do this step every time you restart the simulator). Now place your file you want to read in the folder you want to read from and refer to it as follows:
ex: file is 'simulator directory'/Blackberry/documents/test.txt
then code is
String filePath = "file:///SDCard/documents/test.txt";
FileConnection fc = (FileConnection)Connector.open(filePath,Connector. READ_WRITE);
throw new IOException("File does not exist");
InputStream is = fc.openInputStream();
If you still can't open the file then you have some issue I don't know about (possibly permission issues???)
As for rgholami's case:
Again, it appears that your file does not exist in the simulator environment - I have never written/read a file from the main root "file:///" and don't know if you can do this. So, I'd suggest following the suggestion I gave levantiep above first (try accessing files on the SD Card first), then try moving the file to the device memory (I don't know how you would do this manually but you could write the file out to the device memory programmatically first and then write/read it). As well, in your case if the file you are trying to write to doesn't exist you will get an exception - so you could try to create it with fc.create(); first if it didn't exist using if(!fc.exists()).
Also noticed that you are using static method open for Connector whereas you should probably use the pattern in levantiep's example above and get a FileConnection fc.