file-io

Reading a text file in java

こ雲淡風輕ζ 提交于 2019-12-28 03:04:08
问题 How would I read a .txt file in Java and put every line in an array when every lines contains integers, strings, and doubles? And every line has different amounts of words/numbers. I'm a complete noob in Java so sorry if this question is a bit stupid. Thanks 回答1: Try the Scanner class which no one knows about but can do almost anything with text. To get a reader for a file, use File file = new File ("...path..."); String encoding = "...."; // Encoding of your file Reader reader = new

How to know whether a file copying is 'in progress'/complete in java (1.6) [duplicate]

空扰寡人 提交于 2019-12-28 02:57:44
问题 This question already has answers here : JAVA NIO Watcher: How to detect end of a long lasting (copy) operation? (2 answers) Closed 5 years ago . I am writing a directory monitoring utility in java(1.6) using polling at certain intervals using lastModified long value as the indication of change. I found that when my polling interval is small (seconds) and the copied file is big then the change event is fired before the actual completion of file copying. I would like to know whether there is a

Writing a file using multiple threads

夙愿已清 提交于 2019-12-28 02:45:11
问题 I am trying to write a single huge file in Java using multiple threads. I have tried both FileWriter and bufferedWriter classes in Java. The content being written is actually an entire table (Postgres) being read using CopyManager and written. Each line in the file is a single tuple from the table and I am writing 100s of lines at a time. Approach to write: The single to-be-written file is opened by multiple threads in append mode. Each thread thereafter tries writing to the file file.

Writing data to a local text file with javascript

China☆狼群 提交于 2019-12-28 02:45:09
问题 I have created a procedure to write content to a text file in my local machine. <form id="addnew"> <input type="text" class="id"> <input type="text" class="content"> <input type="submit" value="Add"> </form> <script> jQuery(function($) { $('#form_addjts').submit(function(){ writeToFile({ id: $(this).find('.id').val(), content: $(this).find('.content').val() }); return false; }); function writeToFile(data){ var fso = new ActiveXObject("Scripting.FileSystemObject"); var fh = fso.OpenTextFile("D

Write I/O file to shared network drive using credentials

不羁的心 提交于 2019-12-28 00:59:41
问题 I want to drop a .txt file on a shared network drive. The path is a map on a networkdrive which requires credentials (login and password). Can i pass these parameters using FileOutputStream? FileOutputStream fos; DataOutputStream dos; try { File file= new File(path + "/" + fileName + ".txt"); fos = new FileOutputStream(file); dos=new DataOutputStream(fos); dos.writeChars(stringContent); dos.close(); fos.close(); } catch(IOException eio){ } Thank you. 回答1: No. Use java CIFS Client library. you

Reading two-line headers in R

可紊 提交于 2019-12-27 22:35:41
问题 What is the best way to read a file into R when the header has two necessary lines for the header? This happens to me all the time, as people often use one line for the column name and then include another line underneath it for the unit of measurement. I don't want to skip anything. I want the names and the units to carry through. Here is what a typical file with two headers might look like: trt biomass yield crop Mg/ha bu/ac C2 17.76 205.92 C2 17.96 207.86 CC 17.72 197.22 CC 18.42 205.20

Appending to the end of a file with NSMutableString

这一生的挚爱 提交于 2019-12-27 21:24:53
问题 I have a log file that I'm trying to append data to the end of. I have an NSMutableString textToWrite variable, and I am doing the following: [textToWrite writeToFile:filepath atomically:YES encoding: NSUnicodeStringEncoding error:&err]; However, when I do this all the text inside the file is replaced with the text in textToWrite. How can I instead append to the end of the file? (Or even better, how can I append to the end of the file on a new line?) 回答1: I guess you could do a couple of

Java byte array contains negative numbers

强颜欢笑 提交于 2019-12-27 17:39:27
问题 I'm reading a file into a byte array in chunks and sending it over the network via a POST request to a webserver. It's not anything complicated, I've done it before using this exact same code. This time, I noticed that my images are looking really odd when they get to the server, so I decided to look at the byte array being sent and the one being received just to make sure it was the same. It's not. On the java sending side the byte array contains negative numbers. On the C# receiving side,

Using reflection to change static final File.separatorChar for unit testing?

末鹿安然 提交于 2019-12-27 17:37:29
问题 Specifically, I'm trying to create a unit test for a method which requires uses File.separatorChar to build paths on windows and unix. The code must run on both platforms, and yet I get errors with JUnit when I attempt to change this static final field. Anyone have any idea what's going on? Field field = java.io.File.class.getDeclaredField( "separatorChar" ); field.setAccessible(true); field.setChar(java.io.File.class,'/'); When I do this, I get IllegalAccessException: Can not set static

LOAD DATA INFILE Error Code : 13

拟墨画扇 提交于 2019-12-27 16:41:56
问题 In my remote MySQL, when I try to execute this query, I am getting the MySQL Error Code : 13. Query - LOAD DATA INFILE '/httpdocs/.../.../testFile.csv' INTO TABLE table_temp FIELDS TERMINATED BY ',' LINES TERMINATED BY '\\r \\n' (sku, qty); Error Code : 13 Can't get stat of '/httpdocs/.../.../testFile.csv' (Errcode: 2) a. The database userlogin has all the grant priviliges. CREATE USER 'userName'@'%' IDENTIFIED BY '************'; GRANT ALL PRIVILEGES ON * . * TO 'userName'@'%' IDENTIFIED BY '