text-files

The file is being used by another process, I must close it? How?

随声附和 提交于 2019-12-02 05:01:01
问题 I am using a text file to have some data there for later purposes. So what I do is to check if file exists, if not I am creating a new file when I need. This gives me error saying that my file is still being used by a different process, but I'm not sure why that is. This is how I do it. Here, I am checking if file exists which starts when program runs: private void CreateLastOpenFile() { if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } if (!File.Exists(file)) { File

using log4j for clearing a file?

血红的双手。 提交于 2019-12-02 04:28:22
im using log4j to write into a file with the following properties file : log4j.rootLogger=DEBUG, FA #File Appender log4j.appender.FA=org.apache.log4j.FileAppender log4j.appender.FA.File=temp.ppr log4j.appender.FA.layout=org.apache.log4j.PatternLayout log4j.appender.FA.layout.ConversionPattern= %m%n My problem is , that in each run of my program , i want to clear the file "temp.ppr" , and then write to it efficiently with lo4j? or do you recommend other solutions? thanks You could do this: log4j.appender.FA=org.apache.log4j.RollingFileAppender log4j.appender.FA.MaxBackupIndex=1 And then in the

How to Determine the Max and Min Values Read in From a Text File in Java

让人想犯罪 __ 提交于 2019-12-02 03:44:00
I am doing a homework assignment for a class, and am looking for some helpful pointers, not full solutions. Basically, I have to write a Java program that reads in a text file and lists the information line by line, lists the line number, and finally, prints out the maximum and minimum value and the years that relates to each. The text file contains a year and the temperature for that year. So, it lists something like, "1900 50.9." I am not meant to use an array, or the scanner, this is part of the assignment. I've already been able to successfully get the program to print out each year and

how to write into a text file in Java

霸气de小男生 提交于 2019-12-02 03:17:40
I am doing a project in java and in that i need to add and modify my text file at runtime,which is grouped in the jar. I am using class.getResourceAsStream(filename) this method we can read that file from class path. i want to write into the same textfile. What is the possible solution for this. If i can't update the text file in jar what other solution is there? Appreciate any help. The easiest solution here is to not put the file in the jar. It sounds like you are putting files in your jar so that your user only needs to worry about one file that contains everything related to that program.

know the number of columns from text file, separated by space or tab

自闭症网瘾萝莉.ら 提交于 2019-12-02 02:54:16
I need to know the number of columns from a text file with floats. I've made like this to know the number of lines: inFile.open(pathV); // checks if file opened if(inFile.fail()) { cout << "error loading .txt file for reading" << endl; return; } // Count the number of lines int NUMlines = 0; while(inFile.peek() != EOF){ getline(inFile, dummyLine); NUMlines++; } inFile.close(); cout << NUMlines-3 << endl; // The file has 3 lines at the beginning that I don't read A line of the .txt : 189.53 58.867 74.254 72.931 80.354 The number of values can vary from file to file but not on the same file.

Python program to delete a specific line in a text file [duplicate]

丶灬走出姿态 提交于 2019-12-02 02:16:08
This question already has an answer here: using Python for deleting a specific line in a file 15 answers I have a text file Thailand_Rectangle2_National Parks.txt with the following lines. 1 2 3 4 5 dy 0.5965 7 Now, I want to delete the 6th line in this text file. For that, I am using the following python code. f = open("C:/Users/Sreeraj/Desktop/Thailand_Rectangle2_National Parks.txt","r") lines = f.readlines() So, I saved all the lines of this text file in 'lines'. line6 = lines[5] t = line6[:2] f.close() So, now, I have 't' = "dy" . Now, if t == "dy": f = open("C:/Users/Sreeraj/Desktop

Newline “\n” not Working when Writing a .txt file Python

一世执手 提交于 2019-12-02 02:08:58
问题 for word in keys: out.write(word+" "+str(dictionary[word])+"\n") out=open("alice2.txt", "r") out.read() For some reason, instead of getting a new line for every word in the dictionary, python is literally printing \n between every key and value. I have even tried to write new line separately, like this... for word in keys: out.write(word+" "+str(dictionary[word])) out.write("\n") out=open("alice2.txt", "r") out.read() What do I do? 回答1: Suppose you do: >>> with open('/tmp/file', 'w') as f: ..

Newline “\\n” not Working when Writing a .txt file Python

我们两清 提交于 2019-12-02 00:24:53
for word in keys: out.write(word+" "+str(dictionary[word])+"\n") out=open("alice2.txt", "r") out.read() For some reason, instead of getting a new line for every word in the dictionary, python is literally printing \n between every key and value. I have even tried to write new line separately, like this... for word in keys: out.write(word+" "+str(dictionary[word])) out.write("\n") out=open("alice2.txt", "r") out.read() What do I do? Suppose you do: >>> with open('/tmp/file', 'w') as f: ... for i in range(10): ... f.write("Line {}\n".format(i)) ... And then you do: >>> with open('/tmp/file') as

Extract value containing in a line from a text file using groovy

不羁岁月 提交于 2019-12-01 22:31:14
i want to extract a value of token in a line from a text file. The line from the text file is: <response>{"timestamp": "2013-11-12T14:55:43Z", "data": {"profile": null, "ticket": "f644231-6d46-44c7-add6-de3a4422871e", </response> groovy file is: // read the file from path def file = new File('c:/tmp/response.txt') // for example read line by line def data= file.eachLine { line -> // check if the line contains your data if(line.contains('"ticket":')){ return line } } testRunner.testCase.testSuite.project.setPropertyValue('ticket',data) So here it's not storing any value in my variable ticket.

Extract value containing in a line from a text file using groovy

情到浓时终转凉″ 提交于 2019-12-01 22:28:01
问题 i want to extract a value of token in a line from a text file. The line from the text file is: <response>{"timestamp": "2013-11-12T14:55:43Z", "data": {"profile": null, "ticket": "f644231-6d46-44c7-add6-de3a4422871e", </response> groovy file is: // read the file from path def file = new File('c:/tmp/response.txt') // for example read line by line def data= file.eachLine { line -> // check if the line contains your data if(line.contains('"ticket":')){ return line } } testRunner.testCase