Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Sydan · Sep 21, 2011 at 09:29 PM · javascriptfilereadspecificskip

Reading a specific line from a file.

I'm working in Javascript.

I need to read a specific portion of a file and I don't want to waste time reading the entire file to an array and then selecting the data I need.

I'm using the StreamReader Class, but it doesn't appear to have a SkipLine or Skip method... Is there another way of moving to a specific part of a file for reading?

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
0

Answer by kevork · Sep 21, 2011 at 10:56 PM

You aren't "wasting time" by reading in the previous lines first. In text files, lines are characters, generally '\n', just like all the other characters in the file. There's no way to skip ahead to the Nth line in a generic text file without reading all the previous lines.

I would suggest you for you to not worry about performance issues until they actually become a problem.

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 Sydan · Sep 21, 2011 at 11:07 PM 0
Share

Well unfortunately I do have a problem... I'm currently reading a 32$$anonymous$$B file... quite a lot of the time as well...

Is there a good way of giving the lines 'lines numbers' and then reading the line by its number?

avatar image kevork · Sep 21, 2011 at 11:21 PM 0
Share

It should only take a few seconds to read 32$$anonymous$$B from disk. Unfortunately, you probably want to try to solve this problem in another way. Can you store this data in another format at build time, so it's immediately available at run time? Are you reading this file more than once? Etc.

avatar image Sydan · Sep 22, 2011 at 11:01 AM 0
Share

What other formats might be more suitable? I'm reading this file to update a terrain as the player moves over it. (It's actually a planet but that's beside the point) As the player moves around Unity is currently accessing the file containing the planets terrain and building the area the player can see.

The planet has been split into 1000 chunks in a 3D grid. If a chunk is in view its data is loaded from the file and created in realtime. The problem is that with a large file it really slows down the game as the world is loaded because you're right, it takes a second or two to read the 32$$anonymous$$B file, but it has to do it fairly often when the player is moving.

avatar image syclamoth · Sep 22, 2011 at 11:43 AM 0
Share

Why don't you split the file into 1000 bite-sized chunks? That way you only have to load the bit that you need, and you still get all of your data available.

avatar image Sydan · Sep 22, 2011 at 12:02 PM 0
Share

Do you mean have 1000 different files? Or split the file in a different way?

avatar image
0

Answer by drudiverse · Mar 20, 2016 at 08:21 AM

I believe this does it, puts them all in array, its a bit shorter than parsing manually:

         var arrLine : String[] = File.ReadAllLines(fileName);
         arrLine[line_to_edit - 1] = newText;
         File.WriteAllLines(fileName, arrLine);
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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to make/write to files, then read immediately? 1 Answer

I cant read the file i wrote, unless i reload it in VS. 1 Answer

Best way to manage stats in a text file 2 Answers

Can someone help me fix my Javascript for Flickering Light? 6 Answers

how to read a txt file faster ? my projects' loading time is so long ! about 30 minutes!!! 2 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