file-handling

Create a file descriptor

冷暖自知 提交于 2019-12-06 15:12:48
I want to create a file descriptor in C whose value i will specify in code. I have a integer variable which specifies the value of file descriptor to be created. For example i may need a file descriptor whose value is 5 and later associate that with the file named "sample.dat" . You need dup2() http://linux.die.net/man/2/dup fd = open ("sample.dat", O_RDONLY); open the file dup2 (fd, 5); and copy the file descriptor fd into the descriptor number 5 now you can do read (5, buffer, BUFF_MAX); or also use fd to access the same file. You need to close the fd explicitly if you do not need it. As

Read comma separated values from a text file in C [duplicate]

旧城冷巷雨未停 提交于 2019-12-06 13:43:07
问题 This question already has answers here : read comma-separated input with scanf (2 answers) Read .CSV file in C (4 answers) Closed last year . I am really new to C programming and this is a part of an assignment. I am trying to read a comma separated text file in the format: [value1], [value2] in C and trying to pass them as string and int parameter into a function. I have tried using the sscanf() and even manipulation with fgetc() without much help. The space after the comma is proving to be

FtpWebRequest ListDirectory does not return hidden files

感情迁移 提交于 2019-12-06 09:49:40
Using FtpWebRequest to list the contents of a directory; however, it's not showing the hidden files. How do I get it to show the hidden files? FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftp_root + path); request.Method = WebRequestMethods.Ftp.ListDirectory; FileZilla lists the hidden files correctly so I know the FTP server is returning that data to it. I just need to replicate that with FtpWebRequest . Or use a different library for it. The FtpWebRequest which is provided by Microsoft does not perform all the operations neccessary for listing FTP, FTPS or SFTP site's directories

python - Reading all kinds of files in different encodings

不羁岁月 提交于 2019-12-06 07:27:54
I built a Python steganographer that hides UTF-8 text in images and it works fine for it. I was wondering if I could encode complete files in images. For this, the program needs to read all kinds of files. The problem is that not all files are encoded with UTF-8 and therefore, you have to read them with: file = open('somefile.docx', encoding='utf-8', errors='surrogateescape') and if you copy it to a new file and read them then it says that the files are not decipherable. I need a way to read all kinds of files and later write them so that they still work. Do you have a way to do this in Python

How do I add a file browser inside my Java application?

五迷三道 提交于 2019-12-06 04:43:22
问题 I am new to Java progamming and am building a application that will add, display and remove files from a given folder location. I have added files using JFileChooser and know how to delete the files. However I am stuck with the display portion. I want to display the files and folder using different icon inside my application. I tried to add a JFileChooser inside the display panel and disable the button and menu components of the dialog box, but I have not succeeded. Is there any better way to

How to see file handles like with “lsof -l”?

回眸只為那壹抹淺笑 提交于 2019-12-05 22:52:54
I did the commands ( source ): $ exec 3>/tmp/thirdfile $ exec 4>/tmp/fourthfile $ echo drib >&3 $ echo drab >&4 $ echo another drib >&3 $ echo another drab >&4 $ exec 3>&- $ exec 4>&- How can I see the file handles, something like with lsof -l ? I don't understand, why not just use lsof: lsof -p $$ $$ being a shell variable that holds the shell's process ID You can also limit to just file descriptors like: lsof -a -d0-65535 -p $$ On Linux, you can do something like ls -l /proc/$$/fd , which will show you what file descriptors are open in your shell. Of course, substitute $$ with other numbers

How to Write Multiple Rows/Arrays to CSV File in one attempt using PHP? [closed]

北城余情 提交于 2019-12-05 22:01:00
I have to write multiple records in csv file. I'm using fputcsv function of php which take array as one row and write it in the file. In this way there will be multiple write operations for each row. I'm looking for a method with which I can write multiple rows in one write operation to csv file. Please help. Here's an example using the memory stream. It should give you a structure that you can customize to work through the buffer in pieces and reset progress if the buffer gets too big. <?php // Sample data $arrData = array( array("Fruit","Color","Calories"), array("Apple","Red",95), array(

How should I check if BufferedWriter is already closed?

青春壹個敷衍的年華 提交于 2019-12-05 16:57:39
In android, I am writing a file on clicking a button and on clicking next time, it saves the file and closes the buffered writer. But, I also want to implement functionality to close the buffered writer in onDestroy function. Before that I need to know if Bufferedwriter is already closed. How will I check if Buffered Writer is already closed? In addition to that, does bufferedWriter.close() function set bufferedWriter to null ? Calling close method on already closed Writer has no impact. Still, if you want to know if the Writer is closed, you can call writer.flush() , if it throws IOException

How can I use file_put_contents() with FILE_APPEND | LOCK_EX safety?

删除回忆录丶 提交于 2019-12-05 15:55:01
问题 This question was migrated from Software Engineering Stack Exchange because it can be answered on Stack Overflow. Migrated 7 years ago . I'm using: file_put_contents("peopleList.txt", $person, FILE_APPEND | LOCK_EX); to write to the end of a file and to make sure no one else (or script) is also writing to the same file at the same time. The PHP manual says it will return a falsy value if unsuccessful. If it cannot obtain a lock on the file, will it fail or keep trying until it can? If it does

Can BufferedReader read bytes?

心已入冬 提交于 2019-12-05 15:50:44
问题 Sorry if this question is a dulplicate but I didn't get an answer I was looking for. Java docs says this In general, each read request made of a Reader causes a corresponding read request to be made of the underlying character or byte stream. It is therefore advisable to wrap a BufferedReader around any Reader whose read() operations may be costly, such as FileReaders >and InputStreamReaders. For example, BufferedReader in = new BufferedReader(new FileReader("foo.in")); will buffer the input