How to convert java.io to System.io?(Sharing violation )

Suriya_KalidossSuriya_Kalidoss Member ✭✭✭

I'm trying to extract the zip file for this conversion I have used this code
var fileInputStream = new FileStream(_zipFile, FileMode.Open); var zipInputStream = new ZipInputStream(fileInputStream);
But this error occurs please guide:

Sharing violation on path /storage/emulated/0/XF_Downloads/Recording.zip
at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean anonymous, System.IO.FileOptions options) [0x001b7] in :0
at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode) [0x00000] in :0
at (wrapper remoting-invoke-with-check) System.IO.FileStream..ctor(string,System.IO.FileMode)
at XFDownloadManager.Decompress.UnZip () [0x00001] in D:\Beginning\XFDownloadManager-master\XFDownloadManager\XFDownloadManager.Android\Decompress.cs:34
at XFDownloadManager.Droid.AndroidDownloader.DownloadFile (System.String url, System.String folder) [0x0005c] in D:\Beginning\XFDownloadManager-master\XFDownloadManager\XFDownloadManager.Android\AndroidDownloader.cs:42 }

This is my whole code for decompressing the file
`public class Decompress
{
String _zipFile;
String _location;

    public Decompress(String zipFile, String location)
    { 
        _zipFile = zipFile; 
        _location = location; 
        DirChecker(""); 
    }

    void DirChecker(String dir)
    { 

        var file = new Java.IO.File(_location + dir); 

        if(!file.IsDirectory) { 
            file.Mkdirs ();
        } 
    }

    public void UnZip()
    {


        var fileInputStream = new FileStream(_zipFile, FileMode.Open);
            var zipInputStream = new ZipInputStream(fileInputStream); 
            ZipEntry zipEntry = null; 

            while((zipEntry = zipInputStream.NextEntry)!=null)
            {
            //  Log.Verbose("Decompress", "UnZipping : "=zipEntry.Name);

                if(zipEntry.IsDirectory)
                {
                    DirChecker(zipEntry.Name);
                }
                else
                {
                    var fileOutputStream = new FileOutputStream(_location + zipEntry.Name);

                    for (int i = zipInputStream.Read(); i != -1; i = zipInputStream.Read())
                    {
                        fileOutputStream.Write(i);
                    }

                    zipInputStream.CloseEntry();
                    fileOutputStream.Close();
                }
            }
            zipInputStream.Close();

        //catch (Exception ex)
        //{
        //  Log.Error ("Decompress", "UnZip", ex);
        //}
    }

}`
Tagged:

Best Answer

  • Suriya_KalidossSuriya_Kalidoss ✭✭✭
    Accepted Answer

    The root cause is, like the message says, a "Sharing violation", you are trying to access the file while it is being in use. Like reading and writing at the same time.
    Issue fixed

Answers

  • Suriya_KalidossSuriya_Kalidoss Member ✭✭✭
    Accepted Answer

    The root cause is, like the message says, a "Sharing violation", you are trying to access the file while it is being in use. Like reading and writing at the same time.
    Issue fixed

Sign In or Register to comment.