Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

[C#] System.IO

Discussion in 'Scripting' started by traderain, Jul 25, 2015.

  1. traderain

    traderain

    Joined:
    Jul 7, 2014
    Posts:
    108
    Hi, I have a scipt which acesses a file but why is this not working?
    Code (CSharp):
    1.             System.IO.FileInfo finfo = new FileInfo(path);
    2.             System.IO.StreamReader reader = finfo.OpenText();
    The error is:
    Code (CSharp):
    1. Type `System.IO.FileInfo' does not contain a definition for `OpenText' and no extension method `OpenText' of type `System.IO.FileInfo' could be found (are you missing a using directive or an assembly reference?)
    But i have:
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEditor;
    3. using System.IO;
    4. using System;
    5. using System.Collections.Generic;
    6. using System.Xml;
     
  2. chronochris

    chronochris

    Joined:
    Jun 7, 2015
    Posts:
    61
    try
    Code (CSharp):
    1. var reader = finfo.OpenText();
    and let the compiler figure it out. I don't think system.io.streamreader is correct.

    Edit: Nvm, did some digging it is correct.
     
  3. DonLoquacious

    DonLoquacious

    Joined:
    Feb 24, 2013
    Posts:
    1,667
    Restart Unity.
     
  4. Cameron_SM

    Cameron_SM

    Joined:
    Jun 1, 2009
    Posts:
    915
    Works fine for me, why are you qualifying the types like that?

    If it can't find the FileInfo type when declaring finfo without putting System.IO in front then I'm not sure how new FileInfo(path) is working without also having a System.IO qualification.
     
    traderain and DonLoquacious like this.
  5. traderain

    traderain

    Joined:
    Jul 7, 2014
    Posts:
    108
    It solved itself after a couple restarts. Thanks anyway.