insert /retrieve text file into/from MySQL
-
I have a sample code of insert/retrieve binary file into/from MySQL, it uses FileStream to implement the function. Seems FileStream doesn't work for text file. Can anybody tell what function should I use to retrieve text file from MySQL? Or if you could suggest a sampel code, that will be very helpful. Thanks!
-
I have a sample code of insert/retrieve binary file into/from MySQL, it uses FileStream to implement the function. Seems FileStream doesn't work for text file. Can anybody tell what function should I use to retrieve text file from MySQL? Or if you could suggest a sampel code, that will be very helpful. Thanks!
I don't know why a FileStream wouldn't work for text data but would for binary. Can you post your code that doesn't work so we can have a look?
Affordable and reliable hosting? Click here!
-
I don't know why a FileStream wouldn't work for text data but would for binary. Can you post your code that doesn't work so we can have a look?
Affordable and reliable hosting? Click here!
Hi, Davey: Thanks for your response. Here are my code for text file: String * NCFILE_NAME = "test10.nc"; FileStream * tfs = new FileStream(NCFILE_NAME, FileMode::Open, FileAccess::Read); Char ncbuffer[] = new Char[(int)tfs->Length]; tfs->Read(ncbuffer, 0, ncbuffer->Length); My intention is to read the text from "test10.nc" and write to Char Array ncbuffer[], but tfs->Read(ncbuffer, 0, ncbuffer->Length); cause the error like this: cannot convert parameter 1 from '__wchar_t __gc[]' to 'unsigned char __gc[]' When I did exactly the same for binary file, and define as: FileStream* fs = new FileStream(FILE_NAME, FileMode::Open, FileAccess::Read); Byte buffer[] = new Byte[(int)fs->Length]; fs->Read(buffer,0,buffer->Length); String* extension = "jpg"; // for image file It works fine. So I guess maybe I should use something other than FileStream. But what is it? Could you please give me some ideas about this?
-
I don't know why a FileStream wouldn't work for text data but would for binary. Can you post your code that doesn't work so we can have a look?
Affordable and reliable hosting? Click here!
Hi, Davey: Thanks for your response. Here are my code for text file: String * NCFILE_NAME = "test10.nc"; FileStream * tfs = new FileStream(NCFILE_NAME, FileMode::Open, FileAccess::Read); Char ncbuffer[] = new Char[(int)tfs->Length]; tfs->Read(ncbuffer, 0, ncbuffer->Length); My intention is to read the text from "test10.nc" and write to Char Array ncbuffer[], but tfs->Read(ncbuffer, 0, ncbuffer->Length); cause the error like this: cannot convert parameter 1 from '__wchar_t __gc[]' to 'unsigned char __gc[]' When I did exactly the same for binary file, and define as: FileStream* fs = new FileStream(FILE_NAME, FileMode::Open, FileAccess::Read); Byte buffer[] = new Byte[(int)fs->Length]; fs->Read(buffer,0,buffer->Length); String* extension = "jpg"; // for image file It works fine. So I guess maybe I should use something other than FileStream. But what is it? Could you please give me some ideas about this? Regards, Kevin
-
Hi, Davey: Thanks for your response. Here are my code for text file: String * NCFILE_NAME = "test10.nc"; FileStream * tfs = new FileStream(NCFILE_NAME, FileMode::Open, FileAccess::Read); Char ncbuffer[] = new Char[(int)tfs->Length]; tfs->Read(ncbuffer, 0, ncbuffer->Length); My intention is to read the text from "test10.nc" and write to Char Array ncbuffer[], but tfs->Read(ncbuffer, 0, ncbuffer->Length); cause the error like this: cannot convert parameter 1 from '__wchar_t __gc[]' to 'unsigned char __gc[]' When I did exactly the same for binary file, and define as: FileStream* fs = new FileStream(FILE_NAME, FileMode::Open, FileAccess::Read); Byte buffer[] = new Byte[(int)fs->Length]; fs->Read(buffer,0,buffer->Length); String* extension = "jpg"; // for image file It works fine. So I guess maybe I should use something other than FileStream. But what is it? Could you please give me some ideas about this? Regards, Kevin
Always read the data into a Byte[] rather than a Char[] and it will work for both binary and text files. You shouldn't really need to read it into a char[].