Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by Gizmo_2234 · Jun 21, 2015 at 11:14 AM · errortextfilewrite data

IOException: Sharing violation on path. Please Help!

Hello, I was wondering how i keep getting this error and tried looking it up and got no results! I has hoping that someone could help me. This is the error:


IOException: Sharing violation on path C:\sdcard\Square\Highscores.data System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.IO/FileStream.cs:320) System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share) (wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare) System.IO.StreamWriter..ctor (System.String path, Boolean append, System.Text.Encoding encoding, Int32 bufferSize) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.IO/StreamWriter.cs:124) System.IO.StreamWriter..ctor (System.String path) (wrapper remoting-invoke-with-check) System.IO.StreamWriter:.ctor (string) Highscores+$WriteToFile$59+$.MoveNext () (at Assets/Scripts/Highscores.js:98)


and here is the Write To File code:


function WriteToFile(TextToWriteA: String) { var TextToWrite: String[] = TextToWriteA.Split("\n" [0]); if (System.IO.File.Exists(FilePath + FileName)) {} else { System.IO.File.Create(FilePath + FileName); } yield WaitForSeconds(1); var sw: StreamWriter = new System.IO.StreamWriter(FilePath + FileName); for (var i = 0; i < TextToWrite.length; i++) { sw.WriteLine(TextToWrite[i]); StringToWrite += TextToWrite[i]; } sw.Close(); }


Thanks in Advance!

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Gizmo_2234 · Jun 30, 2015 at 04:07 AM 0
Share

Thanks but I did some more research and found out that streamwriter automatically creates the file if it does not exist.

Thanks for the answer anyways.

avatar image DingHuaqiang · Jul 13, 2016 at 01:15 PM 0
Share

i I also had met the problem like yours, i found my read file is openning,and i colsed,it solved... wtf

2 Replies

· Add your reply
  • Sort: 
avatar image
15

Answer by Flightkick · Jun 21, 2015 at 06:09 PM

It looks like you still have a lock on the file you're trying to write to. And I think it might have something to do with the File.Create() method you're calling right before trying to access it with the StreamWriter.

I'm not familiar with JavaScript but in C# it's possible to dispose the File.Create method right away like:

 File.Create("filepath").Dispose();

Also, In C# it's not necessary to create the file before using the StreamWriter so you can leave the File.Create() part out completely. I'm not sure if it will work in JS though.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ardiawanbagusharisa · Jan 15, 2018 at 03:58 AM 0
Share
  • for this answer. I dunno why unity didn't mention this. They did put an example of using File.Create, but that's it.

avatar image JimmyCushnie · Apr 24, 2018 at 08:30 PM 0
Share

Thanks so much, this is exactly what I needed and I couldn't find it anywhere else on the net.

avatar image
0

Answer by thekinghamza · Jul 12, 2018 at 01:55 AM

You are createing the file in the update (every frame )

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to create and write a text file after compile/build 0 Answers

Invalid File Error 2 Answers

HELP! Erorr! 3 Answers

2D array problem in C# 2 Answers

Access is denied in Windows 8 App 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges