help me in this program
-
i am new to c#.net...i am having 90 text files having image intensity values...i am reading n th row of every text file and write it into newly created text file....i have done this in matlab .i am getting correct output...but in this program i have done something wrong...because of that the no.of columns are not same in each row...i couldn't get the output image....here is the program
private void button1_Click(object sender, EventArgs e)
{try { string path1="c:\\\\Vicky\\\\DATAS\\\\OutputFiles"; string path2 = "\\\\"; string path4 = ".txt"; DirectoryInfo dir1 = new DirectoryInfo(path1); dir1.Create(); DirectoryInfo Dir = new DirectoryInfo(@"C:\\Vicky\\DATAS\\textfiles"); FileInfo\[\] FileList = Dir.GetFiles("c\*.txt",SearchOption.AllDirectories); for(int t=1;t<280;t++) { string path3=Convert.ToString(t); string path=path1+path2+path3+path4; FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write); StreamWriter sw = new StreamWriter(fs); foreach (FileInfo FI in FileList) { FileStream fs1 = FI.OpenRead(); StreamReader sr = new StreamReader(fs1); int i = 1; while (sr.ReadLine() != null) { string d=""; if (t == i) { d = sr.ReadLine(); sw.WriteLine(d); break; } i++; } } } //fs.Close(); //sw.Close(); }
-
i am new to c#.net...i am having 90 text files having image intensity values...i am reading n th row of every text file and write it into newly created text file....i have done this in matlab .i am getting correct output...but in this program i have done something wrong...because of that the no.of columns are not same in each row...i couldn't get the output image....here is the program
private void button1_Click(object sender, EventArgs e)
{try { string path1="c:\\\\Vicky\\\\DATAS\\\\OutputFiles"; string path2 = "\\\\"; string path4 = ".txt"; DirectoryInfo dir1 = new DirectoryInfo(path1); dir1.Create(); DirectoryInfo Dir = new DirectoryInfo(@"C:\\Vicky\\DATAS\\textfiles"); FileInfo\[\] FileList = Dir.GetFiles("c\*.txt",SearchOption.AllDirectories); for(int t=1;t<280;t++) { string path3=Convert.ToString(t); string path=path1+path2+path3+path4; FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write); StreamWriter sw = new StreamWriter(fs); foreach (FileInfo FI in FileList) { FileStream fs1 = FI.OpenRead(); StreamReader sr = new StreamReader(fs1); int i = 1; while (sr.ReadLine() != null) { string d=""; if (t == i) { d = sr.ReadLine(); sw.WriteLine(d); break; } i++; } } } //fs.Close(); //sw.Close(); }
you're writing 279 same files...plus
if (t == i)
{d = sr.ReadLine(); sw.WriteLine(d); break; }
this will break in every first while loop
File.Copy()
can do what you needTVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN% R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
----------------------------------------------- 128 bit encrypted signature, crack if you can
-
i am new to c#.net...i am having 90 text files having image intensity values...i am reading n th row of every text file and write it into newly created text file....i have done this in matlab .i am getting correct output...but in this program i have done something wrong...because of that the no.of columns are not same in each row...i couldn't get the output image....here is the program
private void button1_Click(object sender, EventArgs e)
{try { string path1="c:\\\\Vicky\\\\DATAS\\\\OutputFiles"; string path2 = "\\\\"; string path4 = ".txt"; DirectoryInfo dir1 = new DirectoryInfo(path1); dir1.Create(); DirectoryInfo Dir = new DirectoryInfo(@"C:\\Vicky\\DATAS\\textfiles"); FileInfo\[\] FileList = Dir.GetFiles("c\*.txt",SearchOption.AllDirectories); for(int t=1;t<280;t++) { string path3=Convert.ToString(t); string path=path1+path2+path3+path4; FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write); StreamWriter sw = new StreamWriter(fs); foreach (FileInfo FI in FileList) { FileStream fs1 = FI.OpenRead(); StreamReader sr = new StreamReader(fs1); int i = 1; while (sr.ReadLine() != null) { string d=""; if (t == i) { d = sr.ReadLine(); sw.WriteLine(d); break; } i++; } } } //fs.Close(); //sw.Close(); }
thanks for ur reply....i don't know how file.copy() method is going to help in this program.here i am not copying the file to another path...i am just reading the the same row of every text file and copy it into new file..and u told me that this program will write 279 same files...but i am getting 279 different text files with different memory sizes....
-
i am new to c#.net...i am having 90 text files having image intensity values...i am reading n th row of every text file and write it into newly created text file....i have done this in matlab .i am getting correct output...but in this program i have done something wrong...because of that the no.of columns are not same in each row...i couldn't get the output image....here is the program
private void button1_Click(object sender, EventArgs e)
{try { string path1="c:\\\\Vicky\\\\DATAS\\\\OutputFiles"; string path2 = "\\\\"; string path4 = ".txt"; DirectoryInfo dir1 = new DirectoryInfo(path1); dir1.Create(); DirectoryInfo Dir = new DirectoryInfo(@"C:\\Vicky\\DATAS\\textfiles"); FileInfo\[\] FileList = Dir.GetFiles("c\*.txt",SearchOption.AllDirectories); for(int t=1;t<280;t++) { string path3=Convert.ToString(t); string path=path1+path2+path3+path4; FileStream fs = new FileStream(path, FileMode.Create, FileAccess.Write); StreamWriter sw = new StreamWriter(fs); foreach (FileInfo FI in FileList) { FileStream fs1 = FI.OpenRead(); StreamReader sr = new StreamReader(fs1); int i = 1; while (sr.ReadLine() != null) { string d=""; if (t == i) { d = sr.ReadLine(); sw.WriteLine(d); break; } i++; } } } //fs.Close(); //sw.Close(); }
Take a look at
File.ReadAllLines
method. Now since you know the line number to read, just get that from the array returned. Then once you have read all the files, then write everything to the file in one go. This can be done using in built methods in File class. Also, when you reply to anyone, use reply link in that very post and not your own.जय हिंद
-
thanks for ur reply....i don't know how file.copy() method is going to help in this program.here i am not copying the file to another path...i am just reading the the same row of every text file and copy it into new file..and u told me that this program will write 279 same files...but i am getting 279 different text files with different memory sizes....
nettai wrote:
..but i am getting 279 different text files with different memory sizes....
yes, if you dont mind then your code is very tacky. All you need to do is that read all lines from each text file using
File.ReadAllLines()
as Danish said. That will return string[] and you can rip the line by index then add to the generic string listList
. When you done, write entire list usingFile.WriteAllLines()
(you will need to useToArray()
to get the array from list).TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN% R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
----------------------------------------------- 128 bit encrypted signature, crack if you can