1
我試圖從與BinaryReader
二進制文件讀取。二進制閱讀器跳過指令
這是我打電話給我的閱讀方法:
foreach (Movie film in TreeBuilder.myMovies)
{
if (File.Exists(@"C:\Users\DaPhunk\Documents\Visual Studio 2010\Projects\YLK\Binary\" + film.MovieName + ".txt"))
{
string[] myArray = operationManager.BinaryReading(film.MovieName);
if (myArray != null)
{
this.textStarring.Text = myArray[1];
this.textProduced.Text = myArray[2];
this.textMusic.Text = myArray[3];
this.textYear.Text = myArray[4];
this.textTime.Text = myArray[5];
}
else
{
MessageBox.Show("An error occured");
}
}
這是我的閱讀方法:
public string[] BinaryReading(string name)
{
FileStream myStream = new FileStream(@"C:\Users\DaPhunk\Documents\Visual Studio 2010\Projects\YLK\Binary\" + name + ".txt", FileMode.Open);
BinaryReader reader = new BinaryReader(myStream);
string loadString = reader.ReadString();
string[] loadArray = loadString.Split(',');
reader.Close();
myStream.Close();
return loadArray;
}
現在,這些行內的東西是行不通的。我的文件不是空的,因爲它只是一個字符串,我可以讀取文件中的內容。
我的問題是,我試圖找到什麼是錯用一個破發點,但只要我闖過這一行:
string loadString = reader.ReadString();
我的程序開始再次運行。這怎麼可能?這可以防止我檢查我的String[]
中的內容以及方法調用後的值。
任何想法爲什麼?提前致謝。
更新:
我試着將我的breakpoint
這裏
string[] loadArray = loadString.Split(',');
但我的計劃從未停止,因此一直無法前行。
而且這是我的書面方式方法:
foreach (Movie film in TreeBuilder.myMovies)
{
if (film.MovieName == name)
{
FileStream myStream = new FileStream(@"C:\Users\DaPhunk\Documents\Visual Studio 2010\Projects\YLK\Binary\" + film.MovieName + ".txt", FileMode.Create);
BinaryWriter writer = new BinaryWriter(myStream);
writer.Write(film.MovieName + "," + starring + "," + produced + "," + music + "," + year + "," + lenght);
writer.Close();
myStream.Close();
}
}
我的轉折點是在第一行(的foreach條件) – phadaphunk 2012-04-13 05:33:34
(上一個答案再評論);如果你用'BinaryWriter'編寫了文件,你應該在問題中說清楚,你可能不應該調用'.txt'文件。 – 2012-04-13 05:45:11
謝謝你是這個問題。我更改了所有的.bin擴展名,並且一切正常。 只需將您的評論寫爲答案,以便我可以將其標記爲已接受。 非常感謝! – phadaphunk 2012-04-13 05:48:00