1 Reply Latest reply on Oct 13, 2010 4:39 AM by BhaskerChari

    FileSystem Error!!!!!

    Yue_Hong Level 1

      Here is my sample code:

       

                      var file:File = File.applicationDirectory.resolvePath("testing.txt");
                      var fileStream:FileStream = new FileStream();
                      fileStream.open(file, FileMode.READ);
                      var txt:String = fileStream.readUTFBytes(fileStream.bytesAvailable);
                      fileStream.close();
                      Alert.show(txt, "read from file");

       

      When running, if the file exist, everything running properly. But if the file (testing.txt) is missing, adobe air will shows error message and operation is interrupted:

       

      Error: Error #3003: File or directory does not exist.
          at flash.filesystem::FileStream/open()
          at FileSystem/windowedapplication1_applicationCompleteHandler()[F:\Flex Project\experiment\FileSystem\src\FileSystem.mxml:15]
          at FileSystem/___FileSystem_WindowedApplication1_applicationComplete()[F:\Flex Project\experiment\FileSystem\src\FileSystem.mxml:4]
          at flash.events::EventDispatcher/dispatchEventFunction()
          at flash.events::EventDispatcher/dispatchEvent()
          at mx.core::UIComponent/dispatchEvent()[E:\dev\4.x\frameworks\projects\framework\src\mx\core \UIComponent.as:12528]
          at mx.managers::SystemManager/preloader_preloaderDoneHandler()[E:\dev\4.x\frameworks\project s\framework\src\mx\managers\SystemManager.as:2502]
          at flash.events::EventDispatcher/dispatchEventFunction()
          at flash.events::EventDispatcher/dispatchEvent()
          at mx.preloaders::Preloader/displayClassCompleteHandler()[E:\dev\4.x\frameworks\projects\fra mework\src\mx\preloaders\Preloader.as:555]
          at flash.events::EventDispatcher/dispatchEventFunction()
          at flash.events::EventDispatcher/dispatchEvent()
          at mx.preloaders::SparkDownloadProgressBar/initCompleteHandler()[E:\dev\4.x\frameworks\proje cts\framework\src\mx\preloaders\SparkDownloadProgressBar.as:1078]
          at flash.events::EventDispatcher/dispatchEventFunction()
          at flash.events::EventDispatcher/dispatchEvent()
          at mx.preloaders::Preloader/dispatchAppEndEvent()[E:\dev\4.x\frameworks\projects\framework\s rc\mx\preloaders\Preloader.as:358]
          at mx.preloaders::Preloader/appCreationCompleteHandler()[E:\dev\4.x\frameworks\projects\fram ework\src\mx\preloaders\Preloader.as:563]
          at flash.events::EventDispatcher/dispatchEventFunction()
          at flash.events::EventDispatcher/dispatchEvent()
          at mx.core::UIComponent/dispatchEvent()[E:\dev\4.x\frameworks\projects\framework\src\mx\core \UIComponent.as:12528]
          at mx.core::UIComponent/set initialized()[E:\dev\4.x\frameworks\projects\framework\src\mx\core\UIComponent.as:1627]
          at mx.managers::LayoutManager/doPhasedInstantiation()[E:\dev\4.x\frameworks\projects\framewo rk\src\mx\managers\LayoutManager.as:759]
          at mx.managers::LayoutManager/doPhasedInstantiationCallback()[E:\dev\4.x\frameworks\projects \framework\src\mx\managers\LayoutManager.as:1072]

       

       

       

      How can I prevent the adobe air from showing the error message when the file I try to open is missing and perform some required task for the missing file? Thanks.

        • 1. Re: FileSystem Error!!!!!
          BhaskerChari Level 4

          Hi Yue_Hong,

           

           

          You can check if the file exists or not as shown below:

           

          var file:File = File.applicationDirectory.resolvePath("testing.txt");

          if(file.exists)
          {
              var fileStream:FileStream = new FileStream();
               fileStream.open(file, FileMode.READ);
               var txt:String = fileStream.readUTFBytes(fileStream.bytesAvailable);
               fileStream.close();
               Alert.show(txt, "read from file");

          }

          else

          {

               Alert.show("Text file doesn't exist.");

          }

           

           

          Thanks,

          Bhasker