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
0
Question by Melanina · Feb 26, 2013 at 09:40 AM · serializationresourcespathfilestream

Problem with path in FileStream

         try {
             FileStream fsr = new FileStream(Application.dataPath + @"\Resources\converted.uvtddir ", FileMode.Open, FileAccess.Read);
             BinaryFormatter formatter = new BinaryFormatter();
             Chapters = (IList<Chapter>)formatter.Deserialize(fsr);
             fsr.Close();
         }catch (Exception e){
             Debug.Log(e.Message);
         }

Hello, i have problem with path to file in resource. Everythink WORK excellent in unity editor, but when i build this on windows or android, throw error : Could not find a part of the path "C:...". I'm confused, please help.

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by Tarlius · Feb 26, 2013 at 11:17 AM

You need to store the file as a text asset (with file extension ".bytes") and load it with Resources.Load().

Anything in a /Resources folder will get pre-built into an Asset Bundle when you deploy (as opposed to a normal folder you can navigate to)

You can access the raw bytes by using textAsset.bytes, and with the byte[] you can make a memory stream that can be used in place of the file stream.

(Edit: Updated to include extra info from conversation with OP)

Comment
Add comment · Show 5 · 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 Melanina · Feb 26, 2013 at 12:02 PM 0
Share

so do you have some idea how to get access to this file in built application?

avatar image Tarlius · Feb 26, 2013 at 12:09 PM 1
Share

Change the file extension to .txt Then use something like:

 TextAsset textAsset = (TextAsset) Resources.Load("converted");
 byte[] bytes = textAsset.bytes;
avatar image Melanina · Feb 26, 2013 at 12:22 PM 0
Share

0

I forgot mention that is nested lists with bools, strings and others values, not only text.

avatar image Tarlius · Feb 26, 2013 at 12:40 PM 0
Share

You can use TextAsset for binary data (as odd as that sounds); .bytes will get you the raw bytes.

I think it will also work if you change the extension to .bytes too, which might be a little less confusing. If I recall correctly, unity won't add it if its not an asset-type it recognises though.

I believe you can then turn the byte[] into a $$anonymous$$emoryStream and use it with your above code in place of FileStream.

avatar image Melanina · Mar 04, 2013 at 11:02 AM 0
Share

Ok,work ;) thx for help, if you want edit your answer i used .bytes extension and code should look like this:

 try {
     TextAsset ta = Resources.Load("converted") as TextAsset;
     Stream s = new $$anonymous$$emoryStream(ta.bytes);
     BinaryFormatter formatter = new BinaryFormatter();
     Chapters = (IList<Chapter>)formatter.Deserialize(s);
     s.Close();
 }catch (Exception e){
     Debug.Log(e.$$anonymous$$essage);
 }
avatar image
0

Answer by DaveA · Feb 26, 2013 at 10:30 AM

When built, does that path exist? Is the file there? If not, make that path, and put that file there.

Comment
Add comment · Show 1 · 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 Melanina · Feb 26, 2013 at 11:09 AM 0
Share

yes, file exist in Assets/Resource. When i run my game in editor, i have access to file and everythink work good, but not in built application

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

10 People are following this question.

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

Related Questions

Can't open the file with File.Open/File.OpenRead 1 Answer

serialization stream supports seeking but its length is 0 0 Answers

Resources.Load problem 1 Answer

Can we merge multiple save files for easier management? 1 Answer

Data Persistance, Resources and AssetBundles 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