file-handling

How can I get last modified timestamp in Lua

家住魔仙堡 提交于 2019-12-01 09:06:15
I am trying to work on Lua file handling. So, I am able to open, read, write, close the files. local session_debug = io.open("/root/session_debug.txt", "a") session_debug:write("Some text\n") session_debug:close() How can I know the last modified date timestamp of this file. There's no built-in function in standard Lua that does this. One way to get it without third-party libraries is to take use of io.popen . For example, on Linux, you could use stat : local f = io.popen("stat -c %Y testfile") local last_modified = f:read() Now last_modified is the timestamp of the last modified time of

how to read line by line in android?

£可爱£侵袭症+ 提交于 2019-11-30 16:13:24
i am using this code. try{ // Open the file that is the first // command line parameter FileInputStream fstream = new FileInputStream("config.txt"); // Get the object of DataInputStream DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); while ((br.readLine()) != null) { temp1 = br.readLine(); temp2 = br.readLine(); } in.close(); }catch (Exception e){//Catch exception if any Toast.makeText(getBaseContext(), "Exception", Toast.LENGTH_LONG).show(); } Toast.makeText(getBaseContext(), temp1+temp2, Toast.LENGTH_LONG).show(); but this

Why does my Python code print the extra characters “” when reading from a text file?

邮差的信 提交于 2019-11-30 00:28:09
问题 try: data=open('info.txt') for each_line in data: try: (role,line_spoken)=each_line.split(':',1) print(role,end='') print(' said: ',end='') print(line_spoken,end='') except ValueError: print(each_line) data.close() except IOError: print("File is missing") When printing the file line by line, the code tends to add three unnecessary characters in the front, namely "". Actual output: Man said: Is this the right room for an argument? Other Man said: I've told you once. Man said: No you

how to read line by line in android?

∥☆過路亽.° 提交于 2019-11-29 23:26:54
问题 i am using this code. try{ // Open the file that is the first // command line parameter FileInputStream fstream = new FileInputStream("config.txt"); // Get the object of DataInputStream DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); while ((br.readLine()) != null) { temp1 = br.readLine(); temp2 = br.readLine(); } in.close(); }catch (Exception e){//Catch exception if any Toast.makeText(getBaseContext(), "Exception", Toast

mkdir() is not creating the new directory

喜你入骨 提交于 2019-11-29 09:16:00
I am using Eclipse and jdk1.7. I am making a basic program using file handling, in which an output directory inside the directory is to be made. But when I run the program, the output is showing false and the directory is not made. I thought that the output was false because of the presence of a directory with the same name, but this is not the reason. So I need help. Here is my code: import java.io.File; public class P { public static void main(String[] args) { File f1 = new File ("abc"); File f2 = new File (f1,"abc"); System.out.println(f2.mkdir()); } } Its output is false and yet no

Read contents of a file as hex in C

ぐ巨炮叔叔 提交于 2019-11-29 04:50:50
I have a file with hex values saved as hex.txt which has 9d ff d5 3c 06 7c 0a Now I need to convert it to a character array as unsigned char hex[] = {0x9d,0xff,0xd5,0x3c,0x06,0x7c,0x0a} How do I do it ? use a file read example like from here and with this code read the values: #include <stdio.h> /* required for file operations */ #include <conio.h> /* for clrscr */ FILE *fr; /* declare the file pointer */ main() { clrscr(); fr = fopen ("elapsed.dta", "rt"); /* open the file for reading */ /* elapsed.dta is the name of the file */ /* "rt" means open the file for reading text */ char c; while(c

Php create a file if not exists

好久不见. 提交于 2019-11-29 03:39:29
I try to create files and write the contents dynamically. Below is my code. $sites = realpath(dirname(__FILE__)).'/'; $newfile = $sites.$filnme_epub.".js"; if (file_exists($newfile)) { $fh = fopen($newfile, 'a'); fwrite($fh, 'd'); } else { echo "sfaf"; $fh = fopen($newfile, 'wb'); fwrite($fh, 'd'); } fclose($fh); chmod($newfile, 0777); // echo (is_writable($filnme_epub.".js")) ? 'writable' : 'not writable'; echo (is_readable($filnme_epub.".js")) ? 'readable' : 'not readable'; die; However, it does not create the files. Please share your answers and help. Thanks! Try using: $fh = fopen($newfile

Difference between System.getProperty(“line.separator”); and “\\n” ?

北城以北 提交于 2019-11-29 03:33:36
While developing GUI with Java FX , I seem to get different results with System.getProperty("line.separator"); and "\n" during writing to a file or getting data from internet. What basically is the difference ? System.getProperty("line.separator") returns the OS dependent line separator. On Windows it returns "\r\n" , on Unix "\n" . So if you want to generate a file with line endings for the current operating systems use System.getProperty("line.separator") or write using a PrintWriter . on the Windows platform, System.getProperty("line.separator") is "\r\n", "\n" (Linux and MacOS X), "\r"

java: how to use bufferedreader to read specific line

ぐ巨炮叔叔 提交于 2019-11-29 02:32:50
Lets say I have a text file called: data.txt (contains 2000 lines) How do I read given specific line from: 500-1500 and then 1500-2000 and display the output of specific line? this code will read whole files (2000 line) public static String getContents(File aFile) { StringBuffer contents = new StringBuffer(); try { BufferedReader input = new BufferedReader(new FileReader(aFile)); try { String line = null; while (( line = input.readLine()) != null){ contents.append(line); contents.append(System.getProperty("line.separator")); } } finally { input.close(); } } catch (IOException ex){ ex

How feof() works in C

社会主义新天地 提交于 2019-11-28 20:49:14
Does feof() checks for eof for the current position of filepointer or checks for the position next to current filepointer? Thanks for your help ! Every FILE stream has an internal flag that indicates whether the caller has tried to read past the end of the file already. feof returns that flag. The flag does not indicate whether the current file position is as the end of the file, only whether a previous read has tried to read past the end of the file. As an example, let's walk through what happens, when reading through a file containing two bytes. f = fopen(filename, "r"); // file is opened