Easiest way to read text file which is locked by another application

I think you just want the following: using (var fileStream = new FileStream(“foo.bar”, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) using (var textReader = new StreamReader(fileStream)) { var content = textReader.ReadToEnd(); } The FileAccess.Read parameter is what is important, to indicate that you only want to read the file. Of course, even to do this, the file must have … Read more

How to read a text file directly from Internet using Java?

Use an URL instead of File for any access that is not on your local computer. URL url = new URL(“http://www.puzzlers.org/pub/wordlists/pocket.txt”); Scanner s = new Scanner(url.openStream()); Actually, URL is even more generally useful, also for local access (use a file: URL), jar files, and about everything that one can retrieve somehow. The way above interprets … Read more

How to efficiently write a large text file in C#?

File I/O operations are generally well optimized in modern operating systems. You shouldn’t try to assemble the entire string for the file in memory … just write it out piece by piece. The FileStream will take care of buffering and other performance considerations. You can make this change easily by moving: using (StreamWriter outfile = … Read more

Performance effect of using print statements in Python script

Tried doing it in a very simple script just for fun, the difference is quite staggering: In large.py: target = open(‘target.txt’, ‘w’) for item in xrange(4000000): target.write(str(item)+’\n’) print item Timing it: [gp@imdev1 /tmp]$ time python large.py real 1m51.690s user 0m10.531s sys 0m6.129s gp@imdev1 /tmp]$ ls -lah target.txt -rw-rw-r–. 1 gp gp 30M Nov 8 16:06 … Read more

Comparing text files with Junit

Here’s one simple approach for checking if the files are exactly the same: assertEquals(“The files differ!”, FileUtils.readFileToString(file1, “utf-8”), FileUtils.readFileToString(file2, “utf-8”)); Where file1 and file2 are File instances, and FileUtils is from Apache Commons IO. Not much own code for you to maintain, which is always a plus. 🙂 And very easy if you already happen … Read more

difference between text file and binary file

At the bottom level, they are all bits… true. However, some transmission channels have seven bits per byte, and other transmission channels have eight bits per byte. If you transmit ASCII text over a seven-bit channel, then all is fine. Binary data gets mangled. Additionally, different systems use different conventions for line endings: LF and … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)