filestream

Write function not using the seekp value

白昼怎懂夜的黑 提交于 2019-12-01 06:31:24
I'm trying to use C++ to write an entry in a specific place in a file so basicly I have ofstream ofs("file.dat", ios::binary | ios::app); ofs.seekp(220, ios::beg); ofs.write((char *)&i, sizeof(i)); But no matter what I do it always write at the end of the file. I suppose this is related to iso::app because according to the documentation app (append) Set the stream's position indicator to the end of the stream before each output operation But if I use ate or nothing it always erases the content of the file. Any help would be great :) Yes, it's the ios::app that's causing this behaviour. Replace

Windows Phone 7 : FileStream exception

白昼怎懂夜的黑 提交于 2019-12-01 06:06:40
问题 I try to use FileStream (using namespace System.IO) but I get an exception : Attempt to access the method failed Here is the code : FileStream fs = new FileStream("file.txt", FileMode.Create); I searched on microsoft.com and I found that this error is because I use a bad library reference. But in my project, I compile with mscorlib.dll from folder : C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\Silverlight\v4.0 I need some help, please. 回答1: You will need to use

FileStream locking a file for reading and writing

不想你离开。 提交于 2019-12-01 05:15:39
I have the following code block which is giving me a headache. Logically it should work as I am using the filestream providing the lock within the using statement. When it gets to the line that creates the StreamWriter, it fails saying "the file is not writable". Now my program is a multithreaded application. Any thread could be trying to write to this file. I need the program to lock the file, read the contents, check the contents, then write back any changes. During that process, no other thread should be able to access that file. using (var fs = File.Open(fileLoc, FileMode.Open, FileAccess

Python command line 'file input stream'

佐手、 提交于 2019-12-01 03:28:15
I'm fairly new to python coming from C/C++, I was wondering how I would get my 'main.py' to reconize/use the imput given from a bash shell as: python main.py < text.txt (the file is in plain text) I would use argparse to create an option parser that accepts a file path and opens it. import argparse def main(): parser = argparse.ArgumentParser() parser.add_argument('infile', type='open') args = parser.parse_args() for line in args.infile: print line if __name__ == '__main__': main() If type='open' does not provide enough control, it can be replaced with argparse.FileType('o') which accepts

Writing a File that has the Name of a Device

一曲冷凌霜 提交于 2019-12-01 03:25:57
I have run into something curious. I have a decompiler that extracts information from a binary file. I am extracting a series of objects that I need to write separately to disk as binary files. These objects are graphic models compiled into a library. The objects have names embedded in them and I need to use that name as the file name. I am using : try { // Open file for reading . using (var fileStream = new FileStream(fileName, FileMode.Create, FileAccess.Write)) { // Writes a block of bytes to this stream using data from a byte array. . fileStream.Write(byteArray, 0, byteArray.Length); //

FileStream locking a file for reading and writing

坚强是说给别人听的谎言 提交于 2019-12-01 03:00:13
问题 I have the following code block which is giving me a headache. Logically it should work as I am using the filestream providing the lock within the using statement. When it gets to the line that creates the StreamWriter, it fails saying "the file is not writable". Now my program is a multithreaded application. Any thread could be trying to write to this file. I need the program to lock the file, read the contents, check the contents, then write back any changes. During that process, no other

Http MultipartFormDataContent

ぃ、小莉子 提交于 2019-12-01 02:35:35
I have been asked to do the following in C#: /** * 1. Create a MultipartPostMethod * 2. Construct the web URL to connect to the SDP Server * 3. Add the filename to be attached as a parameter to the MultipartPostMethod with parameter name "filename" * 4. Execute the MultipartPostMethod * 5. Receive and process the response as required * / I have written some code that has no errors, however, the file is not attached. Can someone have a look at my C# code to see if I have written the code incorrectly? Here is my code: var client = new HttpClient(); const string weblinkUrl = "http://testserver

Sql Server FILESTREAM Total File Size

女生的网名这么多〃 提交于 2019-12-01 02:09:41
问题 Is there a query that would get me the total file size of the files that are in the FILESTREAM folder on the disk? 回答1: The following query will return the length in bytes of the filestreamcolumn column: SELECT SUM(DATALENGTH(filestreamcolumn)) FROM filestreamtable; Source 回答2: One disadvantage of Remus' solution is that it will not include the old versions of files that are available for garbage collection. They will no longer be part of logical database, but will still consume disk space

stream.CopyTo - file empty. asp.net

£可爱£侵袭症+ 提交于 2019-12-01 02:07:19
I'm saving an uploaded image using this code: using (var fileStream = File.Create(savePath)) { stream.CopyTo(fileStream); } When the image is saved to its destination folder, it's empty, 0 kb. What could possible be wrong here? I've checked the stream.Length before copying and its not empty. There is nothing wrong with your code. The fact you say "I've checked the stream.Length before copying and its not empty" makes me wonder about the stream position before copying. If you've already consumed the source stream once then although the stream isn't zero length, its position may be at the end of

Asynchronous operations performance

三世轮回 提交于 2019-12-01 01:54:08
One of the features of asynchronous programming in .NET is saving threads during long running operation execution. The FileStream class can be setup to allow asynchronous operations, that allows running (e.g.) a copy operation without virtually using any threads. To my surprise, I found that running asynchronous stream copy performs not only slower, but also uses more processing power than synchronous stream copy equivalent. Is there any benchmark tests were done to compare a synchronous vs asynchronous operation execution (file, network, etc.)? Does it really make sense to perform an