filestream

Difference in using read/write when stream is opened with/without ios::binary mode

情到浓时终转凉″ 提交于 2019-12-28 06:49:27
问题 In my experiments with the following code snippet, I did not find any particular difference whether i created the streams with/without the ios:binary mode: int main() { ifstream ostr("Main.cpp", ios::in | ios::binary | ios::ate); if (ostr.is_open()) { int size = ostr.tellg(); char * memBlock = new char[size + 1]; ostr.seekg(0, ios::beg); ostr.read(memBlock, size); memBlock[size] = '\0'; ofstream file("trip.cpp", ios::out | ios::binary); file.write(memBlock, size); ostr.close(); } } Here I am

How to ensure all data has been physically written to disk?

半城伤御伤魂 提交于 2019-12-27 12:21:57
问题 I understand that .NET FileStream's Flush method only writes the current buffer to disk, but dependent on Windows' disk driver and the hard disk firmware this is no guarantee that the data is actually physically written to disk. Is there a .NET or Win32 method that can give me this guarantee? So if there is power loss one nanosecond after the call to this method comes back, I can still be sure that everything is OK? 回答1: Under Windows, look at FlushFileBuffers (Win32 API). 回答2: Stefan S. said

Reading binary file from sdcard using Stream classes in android

左心房为你撑大大i 提交于 2019-12-25 16:54:26
问题 Can anybody have any idea how to read a binary file which resides in sdcard using Streams, like Inputstream , CountingInputStream or SwappedDataInputStream ? I am using these three streams to read a file which is currently in the Resources folder , but now I want to move that file in sdcard but I cannot change these stream because I have done so much work on it and I cannot roll back my work. I am doing it this way but its giving me FileNotFoundException . I need your help please.

db.mdf is being used by another process

≡放荡痞女 提交于 2019-12-25 01:54:24
问题 Right now by code looks like the following: private void DatabaseIntegrityCheck() { try { string m_checksum; using (FileStream stream = File.OpenRead(@"C:\~\db.mdf")) { SHA256Managed sha = new SHA256Managed(); byte[] checksum = sha.ComputeHash(stream); m_checksum = BitConverter.ToString(checksum).Replace("-", String.Empty); } Console.WriteLine(m_checksum); } catch (Exception ex) { Console.WriteLine("unable to retrieve checksum"); } } When I set a breakpoint in my code to see what the

DocX with filestream doesn't save

主宰稳场 提交于 2019-12-24 19:28:29
问题 So for a project I am creating Résumé's and i need to save them into a docx file. It is a ASP.NET MVC application and for the docx generating I'm using the libray docx to create the document. I can create the file but the filestream doesn't add the content i put into it. Here is a the code i use public ActionResult CVToWord(int id) { var CV = CVDAO.CV.Single(cv => cv.id == id); var filename = "CV - " + CV.firstname + " " + CV.name + " - " + CV.creationdate.ToString("dd MM yyyy") + ".docx";

How to Dispose a list of objects;Does it Free the Memory [duplicate]

99封情书 提交于 2019-12-24 16:46:29
问题 This question already has answers here : Understanding garbage collection in .NET (3 answers) Closed 4 years ago . I have the following class. public class Foo { private string _DirName; private FileStream _MyfileStream; public FileStream MyfileStream { get { return _MyfileStream; } } public string DirName { get { return _DirName; } set { _DirName = value; _MyfileStream = new FileStream(value, FileMode.Create); } } } I have Created a List Of Foo as like the following: List<Foo> FooList = new

Delphi TFileStream.Seek, how to check for invalid seek offset

匆匆过客 提交于 2019-12-24 04:55:14
问题 I am working with TFileStream in Delphi 2006. When I invoke TFileStream.Seek with an offset that is out of bounds I am getting different return values. When I seek to a position below the beginning of the stream, the function returns -1 and if I seek to a beyond the stream size, the function returns what would have been the position in the stream if the stream was that large. Is there a way to check whether a seek operation on the stream was successful? Why does TFileStream.Seek not fail when

SQL Server 2012 Full Text Search on FILESTREAMS with Windows Encrypting File System (EFS)

强颜欢笑 提交于 2019-12-23 19:16:13
问题 This is basically a yes/no question, but it is appreciated if the answer includes supporting references and a how-to if the answer is "yes". Strangely, I couldn't find a definitive answer in MSDN or TechNet, and my instincts and experiments lead me to a "no" conclusion. Is it possible to use Windows EFS with SQL Server 2012's FILESTREAMS and FileTables and have Full Text Search work on those FILESTREAMS? TIA Additional Detail I have a Visual Studio SQL Project created that stamps out DBs with

Alternative to FileStream in C# .NET

橙三吉。 提交于 2019-12-23 13:25:06
问题 In an Visual Studio environment, Project A (ASP.NET) references Project B (C#) in my solution like this: Solution ├─Project B │ ├─data.txt │ └─process.cs (a class BB with static initialization new FileStream("data.txt")) └ Project A (referencces Project B) ├─bin │ └─data.txt (copied from project B each time project B changes) └─Controllers └─mycontroller.cs (references the class BB) The problem is that when I run the application, the working directory is C:\Program Files (x86)\IIS Express\ ,

C# Serializing datacontracts from file

China☆狼群 提交于 2019-12-23 13:18:07
问题 I have a list of Xml messages specifically DataContract messages that i record to a file. And i am trying to deserialize them from file one by one. I do not want to read the whole file into memory at once because i expect it to be very big. I have an implementation of this serialization and that works. I did this by serializing using a FileStream and reading the bytes and using regular expression to determine the end of element. Then taking the element and using DataContractSerializer to get