I’ve tried reading a JPG file using the StreamReader class’ ReadToEnd() method which returns a string.
For some reason though, when I write this string out to a file, it doesn’t open.
Is something lost when reading data into a string?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Strings are for text data. They’re not for binary data – if you use them this way you will lose data (there are encodings you can use which won’t lose data if you’re lucky, but there are subtle issues which still make it a really bad idea.)
If you’re actually dealing with a file, the easiest way of reading the whole thing is to call File.ReadAllBytes. If you have to deal with an arbitrary stream, have a look at ‘Creating a byte array from a stream’.