file-handling

Python - How to read file one character at a time?

允我心安 提交于 2019-12-24 12:25:54
问题 I am learning python file handling. I tried this code to read one character at a time f = open('test.dat', 'r') while (ch=f.read(1)): print ch Why it's not working Here is Error message C:\Python27\python.exe "C:/Users/X/PycharmProjects/Learning Python/01.py" File "C:/Users/X/PycharmProjects/Learning Python/01.py", line 4 while (ch=f.read(1)): ^ SyntaxError: invalid syntax Process finished with exit code 1 回答1: Your syntax is a bit off, your assignment inside the while statement is invalid

watchdog(python) - monitor only one file format and ignore everything else in 'PatternMatchingEventHandler'

你说的曾经没有我的故事 提交于 2019-12-24 07:01:27
问题 I'm running code from this article and made some changes to monitor file creations/additions of only one format, that's .csv in a specified directory. the problem now is: My program breaks(stops monitoring, but keeps running), whenever the new file added is not of .csv format; and to compensate for that, here's what i did with ignore_patterns argument(but the program still stops monitoring after a new file of other format is added): PatternMatchingEventHandler(patterns="*.csv", ignore

Why does calling istream::tellg() affect the behavior of my program?

岁酱吖の 提交于 2019-12-23 12:29:05
问题 I am trying to convert a 24 bit bitmap image into grayscale. #include<iostream> #include<fstream> #include<conio.h> #include<stdio.h> using namespace std; class pixel{ public: unsigned char b; unsigned char g; unsigned char r; void display() { cout<<r<<" "<<g<<" "<<b<<" "; } }p1; using namespace std; int main(){ unsigned char avg; fstream file("image.bmp",ios::binary|ios::in|ios::out); int start; file.seekg(10); file.read((char*)&start,4); file.seekg(start); int i=0; while(!file.eof()){ cout<

How should I check if BufferedWriter is already closed?

隐身守侯 提交于 2019-12-22 08:39:16
问题 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 ? 回答1: Calling close method on already closed Writer has no impact.

Cannot convert value of type [java.lang.String] to required type [org.springframework.web.multipart.MultipartFile] for property

☆樱花仙子☆ 提交于 2019-12-21 21:30:40
问题 I am saving an image file from jsp and renaming it in the controller The problem is that same piece of code is working in one part of the controller and not working in another part of the controller here is the jsp code which is same in both cases:- <div class="form-group "> <label for="photo">Photo:</label> <form:input type="file" class="filestyle" path="studentPhoto" id="studentPhoto" placeholder="Upload Photo" required="required" /> </div> Here is the part of the controller where it is

Parsing a flat file in Java

萝らか妹 提交于 2019-12-21 20:26:40
问题 I have a flat file in which data is stored in position based format For eg. from 1 to 5 - some x value is stored, from 6 to 13 - some y value is stored, from 14 to 18 - some z value is stored and so on.. I need to parse the file and get those values and populate a bean. Can anyone please tell me the best way I can go about it means how I can parse the file.I am using Java 6. 回答1: Non complex, fixed length rows should be very easy in plain java. Why don't you just use plain basic substring? I

File Failure On Open

旧时模样 提交于 2019-12-20 06:47:45
问题 for educational purposes, I am writing a small encryption program (not real encryption). I've restructured the program so all my code is in main to simplify things for myself. My unEncrypted file fails. I don't know why. Here's what I know so far. Using Xcode Tested statements by switching the order which the files are opened (and tested) to verify only the unencrypted file failing: it is Gone to Build Phases >> Copy Files >> Add File, adding both files to Absolute Path I've checked the

Read file from subfolder of application installation folder

萝らか妹 提交于 2019-12-19 11:21:38
问题 I have to read the text content from an .txt file, this file is located in app installed folder, in a subfolder, according to Microsoft docs, I am doing it like this: private async void readMyFile() { // Get the app's installation folder. StorageFolder appFolder = Windows.ApplicationModel.Package.Current.InstalledLocation; // Get a file from a subfolder of the current folder by providing a relative path. string txtFileName = @"\myfolder\myfile.txt"; try { //here my file exists and I get file

How can I get last modified timestamp in Lua

帅比萌擦擦* 提交于 2019-12-19 09:24:00
问题 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. 回答1: 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

Read contents of a file as hex in C

非 Y 不嫁゛ 提交于 2019-12-18 04:21:58
问题 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 ? 回答1: 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 *