file-io

Open with chrome instead of download it [closed]

泪湿孤枕 提交于 2021-02-08 13:52:40
问题 Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 1 year ago . Improve this question I encounter a problem when I try to open a txt file with chrome from my local file system(file:///home/solomon/Desktop/temp2.txt), chrome save another copy in my download folder instead of open it:( I want to open and view any text based file with chrome, because

Reading all text files in a directory in Java?

≯℡__Kan透↙ 提交于 2021-02-08 12:16:07
问题 How would I scan an entire folder in my Java code and then read each text file in to a separate array? What I'm trying to do is have a set of LocationNodes(class I created) on a map app that I'm creating for my college campus/side project for my resume. When the code initializes, I want my app to scan for all text files in my "LocationTextFiles" folder. Each text file has 3 sets of text: Line 0 (the name of the location), Line 1 (Hours the building is open), and Line 2-EOF (description of the

“ValueError: I/O operation on closed file” while writing to a file in a loop

你。 提交于 2021-02-08 11:58:20
问题 I have to divide a file.txt into more files. Here's the code: a = 0 b = open("sorgente.txt", "r") c = 5 d = 16 // c e = 1 f = open("out"+str(e)+".txt", "w") for line in b: a += 1 f.writelines(line) if a == d: e += 1 a = 0 f.close() f.close() So , if i run it it gives me this error : todoController\WordlistSplitter.py", line 9, in <module> f.writelines(line) ValueError: I/O operation on closed file I understood that if you do a for loop the file gets closed so I tried to put the f in the for

How to create instance of class File?

梦想与她 提交于 2021-02-08 10:42:32
问题 I've taken a class file(say Foo.class ) using JFileChooser and stored it in a File class object(say File a ). now I've to read metadata like methods and variables of this Foo.class using reflection APIs. My question is that, I've stored it in a , which is just a File reference variable . So how can I use any API on a File. or any other suggestion for doing so are also welcomed. 回答1: as i understand,first of all you need to convert class file to Class object you can do that via UrlClassLoader

How to create instance of class File?

微笑、不失礼 提交于 2021-02-08 10:41:15
问题 I've taken a class file(say Foo.class ) using JFileChooser and stored it in a File class object(say File a ). now I've to read metadata like methods and variables of this Foo.class using reflection APIs. My question is that, I've stored it in a , which is just a File reference variable . So how can I use any API on a File. or any other suggestion for doing so are also welcomed. 回答1: as i understand,first of all you need to convert class file to Class object you can do that via UrlClassLoader

in python how to mock only the file write but not the file read?

坚强是说给别人听的谎言 提交于 2021-02-08 10:06:30
问题 I am testing a function in which both def foo(): with open('input.dat', 'r') as f: .... with open('output.dat', 'w') as f: .... are used. But I only want to mock the write part. Is it possible to do that? Or some other strategy should be used for testing such a function? with patch('__builtin__.open') as m: foo() would fail to read the data. Thanks in advance. 回答1: I found the following solution: from mock import patch, mock_open with open('ref.dat') as f: ref_output = f.read() with open(

in python how to mock only the file write but not the file read?

泪湿孤枕 提交于 2021-02-08 10:05:10
问题 I am testing a function in which both def foo(): with open('input.dat', 'r') as f: .... with open('output.dat', 'w') as f: .... are used. But I only want to mock the write part. Is it possible to do that? Or some other strategy should be used for testing such a function? with patch('__builtin__.open') as m: foo() would fail to read the data. Thanks in advance. 回答1: I found the following solution: from mock import patch, mock_open with open('ref.dat') as f: ref_output = f.read() with open(

Java open file on shared location

a 夏天 提交于 2021-02-08 07:44:30
问题 I want to do something like this: File root = new File("C:/file.txt"); but on a folder which is shared on a local network. So lets say the file is on 192.168.1.28 how make it with above command? Next not working: File root = new File("//192.168.1.2/file.txt"); File root = new File("\\\\192.168.1.2/file.txt"); File root = new File("\\192.168.1.2/file.txt"); File root = new File("file:\\192.168.1.2/file.txt"); File root = new File("file://192.168.1.2/file.txt"); Thanks a lot. 回答1: I think it is

Put A String In A ifstream Method [duplicate]

匆匆过客 提交于 2021-02-07 22:01:49
问题 This question already has an answer here : No matching function - ifstream open() (1 answer) Closed 5 years ago . I'm learning C++ and i'm getting some troubles when i'm trying to use a String in a ifstream method, like this: string filename; cout << "Enter the name of the file: "; cin >> filename; ifstream file ( filename ); Here is the full code: // obtaining file size #include <iostream> #include <fstream> using namespace std; int main ( int argc, char** argv ) { string file; long begin

Does fp.readlines() close a file?

廉价感情. 提交于 2021-02-07 20:39:13
问题 In python I'm seeing evidence that fp.readlines() is closing the file when I try to access the fp later in the program. Can you confirm this behavior, do I need to re-open the file again later if I also want to read from it again? Is the file closed? is similar, but didn't answer all of my questions. import sys def lines(fp): print str(len(fp.readlines())) def main(): sent_file = open(sys.argv[1], "r") lines(sent_file) for line in sent_file: print line this returns: 20 回答1: Once you have read