file-writing

overwriting a specific line on a text file?

痞子三分冷 提交于 2020-01-10 20:09:09
问题 how do I go about overwriting a specific line on a text file in c?. I have values in multiple variables that need to be written onto the file. 回答1: This only works when the new line has the same size as the old one: Open the file in the mode a+ fseek() to the start of the file Before reading the next line, use ftell() to note the start of the line Read the line If it's the line you want, fseek() again with the result from ftell() and use fwrite() to overwrite it. If the length of the line

How to find the size of a ReadableByteChannel in Java?

牧云@^-^@ 提交于 2020-01-07 02:47:26
问题 I am converting a blob from a database into a PDF, using Java's Channel classes. When using a Channel's transferFrom( ) method, you are supposed to specify the maximum number of bytes to be transferred. How are you supposed to find this maximum number of bytes when ReadableByteChannels don't have a size( ) method like other Channels? Is a ReadableByteChannel not the right tool for the job since it doesn't have a size( ) method? I'm just using Long.MAX_VALUE which doesn't seem right. Example

Special characters in filename java

限于喜欢 提交于 2020-01-04 12:48:32
问题 I'm trying to write a file with special characters in filename, for examplo "tééé ê.mp3", but the filename always stay with "?" instead the character "é", I tried a several methods but i didn't found a solution: String musicName = new String("tééé ê.mp3".getBytes(), "UTF-8"); OutputStreamWriter bw = new OutputStreamWriter(new FileOutputStream(FILE_PATH+"musics/"+musicName), "UTF-8"); bw.write(data); bw.close(); I tried this way too. OutputStreamWriter bw = new OutputStreamWriter(new

Creating a text file with the current date and time as the file name in Java [duplicate]

早过忘川 提交于 2019-12-31 07:43:07
问题 This question already has answers here : Name a file in Java to include date and time stamp (3 answers) Closed 3 years ago . I am trying to create a text file and add some details into it using Java when a button is clicked in my GUI application, the name of the text file has to be the current date and time and the location of the text file has to be relative. Here is the code snippet I used to do this. public void actionPerformed(ActionEvent e){ SimpleDateFormat dateFormat = new

DOS batch : Different behaviour between command line and drag and drop

我的未来我决定 提交于 2019-12-25 03:18:07
问题 I'm trying to write the first argument of a command line in a file, but it works in command line and not with drag and drop. The very simple batch file ( test_echo.cmd ) is as following: @echo OFF echo %1 > echo_arg_in_file.txt` On the command line, C:\rep>test_echo.cmd "C:\rep\fichier de test.txt"` creates a file echo_arg_in_file.txt with "C:\rep\fichier de test.txt" written inside. But with a drag and drop of the file "C:\rep\fichier de test.txt" on the batch file, nothing happens... (the

Objective C write to Remote URL

怎甘沉沦 提交于 2019-12-25 01:49:34
问题 Ok, so I have the correct username / pass for a remote host, and I have a NSURL Object referring to the file on the server. How can I possibly write data to that server via Objective-C? I cannot find anyone with this problem, so you help would be greatly appreciated! 回答1: I do it all the time with the program I am writing. The answer depends on what server you have installed and what languages it supports. If, as I think, you have PHP, just send a GET request to your server and instruct the

Consecutive writings to files in the server are slow

…衆ロ難τιáo~ 提交于 2019-12-24 12:29:59
问题 I want to build a simple playground with MEAN stack that mimics plunker: we have a list of files and a textarea on the left hand, and a live preview on the right hand. Note that the files are saved in a temporary folder, and the live preview is an iframe injected by the files from that temporary folder. I have coded something. In the front-end, the controller watches on modifications of files in the textarea; each time there is a change, render will be called and it will send a $http.post to

Cannot write to file on Google App Engine Dev server with PHP?

旧巷老猫 提交于 2019-12-24 12:16:39
问题 I had this working literally just a few hours ago. Not sure what I did to mess it up, if anything. I am trying to use file_put_contents() to a test.txt file in my temp directory to test some stuff. I can't use print_r() or echo, because sometimes it is an ajax call I am testing. The errors I keep getting are: Warning: file_put_contents(temp/test.txt): The local filesystem is readonly, open failed in sub-dirs.../request.php on line 62 Warning: file_put_contents(temp/test.txt): failed to open

How to put new line in php file fwrite

纵然是瞬间 提交于 2019-12-23 06:26:17
问题 I am writing a file that is plan.php . It is a php file that I am writing. I am using \n to put the new line in that file but it is giving me save output. Here is code: $datetime = 'Monthly'; $expiry = '2017-08-07'; $expiryin = str_replace('ly', '',$datetime); if($expiryin == 'Month' || $expiryin == 'Year') { $time = '+ 1'.$expiryin.'s'; } else { $time = '+'.$expiryin.'s'; } $expiry_date = date('Y-m-d', strtotime($time, strtotime($expiry))); $string = createConfigString($expiry_date); $file =

Include table header when writing matrix to file

ぃ、小莉子 提交于 2019-12-23 04:47:11
问题 I write a matrix from Matlab to a file using dlmwrite : A = [1,2,3; 4,5,6; 7,8,9]; dlmwrite('output.txt', A, 'delimiter','\t'); This gives me this output.txt : 1 2 3 4 5 6 7 8 9 Now I would like to add a header to have the following result: columnA columnB columnC 1 2 3 4 5 6 7 8 9 How can I achieve that? 回答1: Headers = ['columnA', 'columnB', 'columnC']; dlmwrite('output.txt', Headers, 'delimiter','\t'); A = [1,2,3; 4,5,6; 7,8,9]; dlmwrite('output.txt', A, 'delimiter','\t','-append'); using