file-io

Java reading nth line

我是研究僧i 提交于 2020-01-02 04:08:08
问题 I am trying to read a specific line from a text file, however I don't want to load the file into memory (it can get really big). I have been looking but every example i have found requires either to read every line (this would slow my code down as there are over 100,000 lines) or load the whole thing into an array and get the correct element (file will have alot of lines to input). An example of what I want to do: String line = File.getLine(5); "code is not actual code, it is made up to show

Is there any difference between text and binary mode in file access?

拈花ヽ惹草 提交于 2020-01-02 03:46:28
问题 Is there any difference if I open a file in text mode rather than binary mode? Because I read that UNIX and Linux make no distinction between text and binary files. 回答1: There is no difference on Linux (at least on native file systems like Ext4 and on most other file systems too, with the usual GNU libc). Perhaps some bizarre filesystems could have a specific flag to open differently binary or text files. I know no such filesystem. Maybe you could code some FUSE filesystem making the

Why is line-seq returning clojure.lang.Cons instead of clojure.lang.LazySeq?

谁说我不能喝 提交于 2020-01-02 03:31:08
问题 According to the ClojureDocs entry for line-seq (http://clojuredocs.org/clojure_core/clojure.core/line-seq) and the accepted answer for the Stack question (In Clojure 1.3, How to read and write a file), line-seq should return a lazy seq when passed a java.io.BufferedReader. However when I test this in the REPL, the type is listed as clojure.lang.Cons. See the code below: => (ns stack-question (:require [clojure.java.io :as io])) nil => (type (line-seq (io/reader "test-file.txt"))) clojure

open(file) from anywhere

杀马特。学长 韩版系。学妹 提交于 2020-01-02 02:40:31
问题 Working on OS X Lion, I'm trying to open a file in my python-program from anywhere in the terminal. I have set the following function in my .bash_profile: function testprogram() {python ~/.folder/.testprogram.py} This way I can(in the terminal) run my testprogram from a different directory than my ~/. Now, if I'm in my home directory, and run the program, the following would work infile = open("folder2/test.txt", "r+") However, if I'm in a different directory from my home-folder and write

Writing data to App_Data

有些话、适合烂在心里 提交于 2020-01-02 02:20:08
问题 I want to write a .xml file using the following code into the App_Data/posts. Why is it causing an error? Code Stream writer = new FileStream("..'\'App_Data'\'posts'\'" + new Guid(post_ID.ToString()).ToString() + ".xml", FileMode.Create); 回答1: Please post the exception you are getting; not just "it does not work" - this can be all sorts of problems. Here is a few things to check: Check whether the ASP.NET process has write access to that directory. Also, it looks like you are escaping the

Why is file_get_contents faster than memcache_get?

浪子不回头ぞ 提交于 2020-01-02 02:17:09
问题 I'm loading XML files from disk using file_get_contents, and as a test I find I can load a 156K file using file_get_contents() 1,000 times in 3.99 seconds. I've subclassed the part that does the loading and replaced it with a memcache layer, and on my dev machine find I can do 1000 loads of the same document in 4.54 seconds. I appreciate that file_get_contents() will do some caching, but it looks like it is actually faster than a well-known caching technique. On a single server, is the

MalformedInputException when trying to read entire file

耗尽温柔 提交于 2020-01-02 01:59:09
问题 I have a 132 kb file (you can't really say it's big) and I'm trying to read it from the Scala REPL, but I can't read past 2048 char because it gives me a java.nio.charset.MalformedInputException exception These are the steps I take: val it = scala.io.Source.fromFile("docs/categorizer/usig_calles.json") // this is ok it.take(2048).mkString // this is ok too it.take(1).mkString // BANG! java.nio.charset.MalformedInputException: Input length = 1 at java.nio.charset.CoderResult.throwException

How do I write a text file in the same format that it is read in MATLAB?

爱⌒轻易说出口 提交于 2020-01-01 19:47:10
问题 I have asked a related question in the past and I know how to read the file thanks to the help of the experts here. Now I have a new problem. I first read the data from the file like so: fid = fopen('D:\file.txt', 'rt'); a = textscan(fid, '%s %f %f %f %f %f %f', ... 'Delimiter',',', 'CollectOutput',1, 'HeaderLines',1); fclose(fid); I then process the file and change a few values of the column. Now I want to write a new file newfile.txt in the exact same format as my file.txt with the new

Delete currently loaded assembly

穿精又带淫゛_ 提交于 2020-01-01 19:13:10
问题 In my application comes with an uninstaller. Everything is working fine, except that I can't find no way to delete the uninstaller.exe file when it's all done. I tried to copy the current assembly exe into a temp directory, but the file-handle of the original file is still locked. Any ideas? 回答1: You will need to PInvoke to do this. MoveFileEx has the ability to schedule deleting the file on next reboot. If dwFlags specifies MOVEFILE_DELAY_UNTIL_REBOOT and lpNewFileName is NULL, MoveFileEx

Reading text from file and storing each word from every line into separate variables

让人想犯罪 __ 提交于 2020-01-01 17:09:16
问题 I have a .txt file with the following content: 1 1111 47 2 2222 92 3 3333 81 I would like to read line-by-line and store each word into different variables. For example: When I read the first line "1 1111 47", I would like store the first word "1" into var_1 , "1111" into var_2 , and "47" into var_3 . Then, when it goes to the next line, the values should be stored into the same var_1 , var_2 and var_3 variables respectively. My initial approach is as follows: import java.io.*; class