filestream

FileStream with DeleteOnClose File option

北城以北 提交于 2019-12-21 01:15:23
问题 In my project I have to create some temp files in an USB device, which I want to delete on Closing. So I used a code like this.fcommandHandler = new FileStream(TempFileName, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.ReadWrite, 512, FileOptions.DeleteOnClose); It works fine. But the problem is I want to use one more FileOption, like No buffering. private const FileOptions FILE_FLAG_NO_BUFFERING = (FileOptions)0x20000000; this.fcommandHandler = new FileStream(TempFileName, FileMode

inotify - how to find out which user has modified file?

跟風遠走 提交于 2019-12-20 20:39:06
问题 I'm looking for guidance on how to find out which user has modified a particular file. While inotify is great to get notification when a particular file is touched, how do I figure out which user has modified that file? I can think of using lsof but I'm afraid that it may not be as "realtime" as I want and/or it might be too much of a tax on resources. By realtime, I mean that if a user simply executes a touch command on a file, by the time I run lsof on file, it may not be picked up by lsof

How do I convert encoding of a large file (>1 GB) in size - to Windows 1252 without an out-of-memory exception?

你离开我真会死。 提交于 2019-12-20 18:05:33
问题 Consider: public static void ConvertFileToUnicode1252(string filePath, Encoding srcEncoding) { try { StreamReader fileStream = new StreamReader(filePath); Encoding targetEncoding = Encoding.GetEncoding(1252); string fileContent = fileStream.ReadToEnd(); fileStream.Close(); // Saving file as ANSI 1252 Byte[] srcBytes = srcEncoding.GetBytes(fileContent); Byte[] ansiBytes = Encoding.Convert(srcEncoding, targetEncoding, srcBytes); string ansiContent = targetEncoding.GetString(ansiBytes); // Now

BufferedReader.readLine() do not read and hang the system(wait) [closed]

牧云@^-^@ 提交于 2019-12-20 07:08:49
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . BufferedReader.readLine() do not read and hang the system(wait) . InputStream istrm = runtimeProcess.getInputStream(); InputStreamReader istrmrdr = new InputStreamReader(istrm); BufferedReader buffrdr = new

as3 URLRequest and file stream saving xml data - Error #3013: File or directory is in use

回眸只為那壹抹淺笑 提交于 2019-12-20 05:13:24
问题 My end goal is to open an xml file, change data and save it. I am opening it with a URLRequest. I am able to change the xml, however, MY ISSUE IS: When I try to open it with a stream to save the file then it says: Error: Error #3013: File or directory is in use. I suppose I could open it with the same stream but then I don't know how to get the xml vars like I do in my script when I am using the URLRequest. So I either need to a) close the xml file so I can open it with a stream or b) open

The bytes my server program receives is incomplete. Why? I'm using C# .net sockets

情到浓时终转凉″ 提交于 2019-12-20 04:50:44
问题 This doesn't always happen. But it happens more often than receiving the bytes completely. This is how my client prog sends bytes to my server prog: public void sendBytes() { FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); TcpClient cli = tcpServer; //tcpServer is a global TcpClient variable I use to connect to the server. NetworkStream ns = cli.GetStream(); CopyStreamToStream(fs, ns, null); ns.Flush(); } public static void CopyStreamToStream

FileStream Append Data at the top

帅比萌擦擦* 提交于 2019-12-20 04:32:47
问题 I am working on a utility. I want to append data at the top of the file, but it is overwritting not appending. For eg : Consider the file.txt : Something existing here Now I want to append "Something more existing here" before the current line. Is there a way I can do without using 2 FileStreams ? 回答1: No. File systems basically don't support inserting data into the file - you either append at the end of the file, or overwrite existing data. At least, I don't know of any file system that does

Using C# is it possible to test if a lock is held on a file

空扰寡人 提交于 2019-12-20 03:27:06
问题 BACKGROUND: I use an offset into a file and the Filestream lock/unlock menthods to control read/write access. I am using the following code to test if a lock is currently held on the file try { fs.Lock( RESERVED_BYTE, 1 ); fs.Unlock( RESERVED_BYTE, 1 ); rc = 1; } catch { rc = 0; } QUESTION: My goal is to eliminate the try/catch block. Is there some better way to see if the lock exists? EDIT: Note: This question is not about if the file exists. I already know it does. It is about synchronizing

Pro & Cons of storing files(pictures) in a SQL Server for a website

余生颓废 提交于 2019-12-20 03:07:30
问题 I'm creating an Asp.Net MVC website. I've in the past, for heavy application, multiple layer application, used the database to store files. But now I'm questioning myself, is this a good idea for a website? In a performance view? It has several pros to me: Allows me to control easily if the connected user has the right to display the image(Required for my project) Permits to be sure that we have consistent data(otherwise we can have an existing file but no info in the database and the

skipws flag set when opening an input file stream in binary mode

爷,独闯天下 提交于 2019-12-20 02:43:06
问题 I know the extraction operator should not be used on an input stream opened in binary mode, but the member function read should be used instead. std::ifstream ifs("file.bin", std::ios::in | std::ios::binary); char c; ifs >> c; // Should not be used ifs.read(&c, 1); // OK But it can be done anyway. So my question is what is the rationale for not unsetting the skipws flag on input file streams when opened in binary mode? 回答1: "Binary" mode, as controlled by std::ios_base::binary is only for