Quantcast

file input output operations

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

file input output operations

John Murray

Can anyone tell me why these lines of code  work

-------------------------------

 

Stream mystream2 = Assets.Open("airfields2.xml");

XDocument xt = XDocument.Load(mystream2); 

 

-----------------------

But this just chucks me out of the program (it stalls in the debugger on the Filestream line)

 

     mystr = GetFileStreamPath("LastGar.xml").ToString();          

      Stream mystream3 = new FileStream(mystr, FileMode.Open); //****PROBLEM ****//

      XDocument xt = XDocument.Load(mystream2);  //shergar.xml

 

This following,  I believe, is an Android way of doing things but this still chucks me out at the problem line marked //****PROBLEM*//

   public void readjavastyle()

{            string mystr = "";

            mystr = GetFileStreamPath("LastGar.xml").ToString();           

            try

            {

                 FileInputStream mystream = OpenFileInput("LastGar.xml"); //***********PROBLEM *****/

            } catch (Java.IO.FileNotFoundException ioe) {

                      Toast.MakeText(this, "file not found error "+ ioe.Cause.ToString(),ToastLength.Long).Show();

            }         

             Toast.MakeText(this, "filestream path " + mystr,ToastLength.Long).Show();                       

            }

}

 

Why can one read an xml file from the Assets included in project but not from the internal storage?

Why doesn't the Android 'OpenfileInput()' work ? If you search StackOverflow etc there are examples which state how 'simple'  (ha ha ) all this is

 

Is this some Android issue - like permissions to read - or another Mono idiosynchracy

if so why can I successfully write the file like this ?

  public void writeAndroidJavaGarXml()

        {

            String string1 = "<?xml version=\"1.0\" standalone=\"yes\"?>";

        try{

            Java.IO.File file = new Java.IO.File(Android.OS.Environment.DataDirectory, "LastGar.xml");

            BufferedWriter writer = new BufferedWriter(new FileWriter(file));

            writer.Write(string1);

            writer.NewLine();

etc etc ............................................

 

------------------------------  

 

I be grateful (nay desperate) for any suggestions - no doubt it works on everyone else's machine J

 

TIA

 

John Murray

 

 

 

 


_______________________________________________
Monodroid mailing list
[hidden email]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: file input output operations

Dennis Quebe

John: What is the actual exception and message that you are catching and getting returned? You have it specifically just trying to catch FileNotFoundException. If it was a different exception, you would not catch it and it would stop the whole application.  Under Project Properties (Visual Studio) or Project Options (MonoDevelop), there is a Mono for Android Manifest (create it if one doesn’t already exists) that defines what permissions your application requires. I didn’t look too hard at the code, but I thought I point you in this direction first.

 

Thanks.

Dennis

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of John Murray
Sent: Saturday, April 16, 2011 10:12 AM
To: 'Discussions related to Mono for Android'
Subject: [mono-android] file input output operations

 

Can anyone tell me why these lines of code  work

-------------------------------

 

Stream mystream2 = Assets.Open("airfields2.xml");

XDocument xt = XDocument.Load(mystream2); 

 

-----------------------

But this just chucks me out of the program (it stalls in the debugger on the Filestream line)

 

     mystr = GetFileStreamPath("LastGar.xml").ToString();          

      Stream mystream3 = new FileStream(mystr, FileMode.Open); //****PROBLEM ****//

      XDocument xt = XDocument.Load(mystream2);  //shergar.xml

 

This following,  I believe, is an Android way of doing things but this still chucks me out at the problem line marked //****PROBLEM*//

 

   public void readjavastyle()

{            string mystr = "";

            mystr = GetFileStreamPath("LastGar.xml").ToString();           

            try

            {

                 FileInputStream mystream = OpenFileInput("LastGar.xml"); //***********PROBLEM *****/

            } catch (Java.IO.FileNotFoundException ioe) {

                      Toast.MakeText(this, "file not found error "+ ioe.Cause.ToString(),ToastLength.Long).Show();

            }         

             Toast.MakeText(this, "filestream path " + mystr,ToastLength.Long).Show();                       

            }

}

 

Why can one read an xml file from the Assets included in project but not from the internal storage?

Why doesn't the Android 'OpenfileInput()' work ? If you search StackOverflow etc there are examples which state how 'simple'  (ha ha ) all this is

 

Is this some Android issue - like permissions to read - or another Mono idiosynchracy

if so why can I successfully write the file like this ?

  public void writeAndroidJavaGarXml()

        {

            String string1 = "<?xml version=\"1.0\" standalone=\"yes\"?>";

        try{

            Java.IO.File file = new Java.IO.File(Android.OS.Environment.DataDirectory, "LastGar.xml");

            BufferedWriter writer = new BufferedWriter(new FileWriter(file));

            writer.Write(string1);

            writer.NewLine();

etc etc ............................................

 

------------------------------  

 

I be grateful (nay desperate) for any suggestions - no doubt it works on everyone else's machine J

 

TIA

 

John Murray

 

 

 

 

 

 


_______________________________________________
Monodroid mailing list
[hidden email]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid
Loading...