0

I currently have a application that reads back the contents of the text file in a string. I want to put all those values in a double array I have created but can't seem to get it to work here is my code :

using (StreamReader sr = new StreamReader("test.txt"))
{
    String line =  sr.ReadToEnd();
    x = doubles;
    Console.WriteLine(x);
}

Everytime I run it I get the error "file could not be read: input string was not in a correct format" Does anyone have any idea whats wrong?

8
  • 2
    What is x what is doubles? Commented Apr 11, 2013 at 13:57
  • 1
    try to use the full filename instead of just "test.txt" Commented Apr 11, 2013 at 13:57
  • Show us how you define and initalise your double array. Commented Apr 11, 2013 at 13:57
  • file could not be read: input string was not in a correct format is that the literal text of the exception? I'm pretty sure it's not. We can't really help unless we know the literal exception text. Commented Apr 11, 2013 at 13:59
  • this is how i define x : double[] x = new double [3501]; Commented Apr 11, 2013 at 14:05

2 Answers 2

1
bool bSuccess;
double value;
bSuccess = double.TryParse("3.14", out value);
Sign up to request clarification or add additional context in comments.

3 Comments

This answers his implied question, but if you re-read the OP's question, the problem is on reading the file.
if you reread the title, you will find it different. so let's wait OP to clarify.
double[] x = new double [3501]; double[] doubles = Array.ConvertAll(line.Split('\n'), new Converter<String, double>(Double.Parse));
0

Make sure that your file path is delcared for the StreamReader, simply stating "test.txt" with no apparent location does not access the file you are attempting to read from.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.