file-io


Traditional IO vs memory-mapped

荒凉一梦 提交于 2020-01-23 01:24:09
问题 I'm trying to illustrate the difference in performance between traditional IO and memory mapped files in java to students. I found an example somewhere on internet but not everything is clear to me, I don't even think all steps are nececery. I read a lot about it here and there but I'm not convinced about a correct implementation of neither of them. The code I try to understand is: public class FileCopy{ public static void main(String args[]){ if (args.length < 1){ System.out.println(" Wrong

pretty print to a file in ruby

大憨熊 提交于 2020-01-22 10:34:09
问题 I am trying to pretty print a hash to a file. I tried unix redirects [added different flags to it incrementally] : `echo #{pp mymap} | tee summary.out 2>&1` and File IO my_file = File.new(@dir_+"/myfile.out",'w+') my_file.puts `#{pp get_submap_from_final(all_mapping_file,final_map)}` It always prints to console and doesnt write to a file. Also there has to be an easier way to write to file in one line in ruby ? instead of doing File.new and then writing to a file ? 回答1: require 'pp' File.open

pretty print to a file in ruby

扶醉桌前 提交于 2020-01-22 10:33:13
问题 I am trying to pretty print a hash to a file. I tried unix redirects [added different flags to it incrementally] : `echo #{pp mymap} | tee summary.out 2>&1` and File IO my_file = File.new(@dir_+"/myfile.out",'w+') my_file.puts `#{pp get_submap_from_final(all_mapping_file,final_map)}` It always prints to console and doesnt write to a file. Also there has to be an easier way to write to file in one line in ruby ? instead of doing File.new and then writing to a file ? 回答1: require 'pp' File.open

Faster way of copying data in Java?

馋奶兔 提交于 2020-01-22 10:07:05
问题 I have been given a task of copying data from a server. I am using BufferedInputStream and output stream to copy the data and I am doing it byte by byte. Even though it is running but It is taking ages to copy the data as some of them are in 100's MBs, so definitely it is not gonna work. Can anyone suggest me any alternate of Byte by Byte copy so that my code can copy file that are in few Hundred MBs. Buffer is 2048. Here is how my code look like: static void copyFiles(SmbFile[] files, String

Faster way of copying data in Java?

北慕城南 提交于 2020-01-22 10:06:07
问题 I have been given a task of copying data from a server. I am using BufferedInputStream and output stream to copy the data and I am doing it byte by byte. Even though it is running but It is taking ages to copy the data as some of them are in 100's MBs, so definitely it is not gonna work. Can anyone suggest me any alternate of Byte by Byte copy so that my code can copy file that are in few Hundred MBs. Buffer is 2048. Here is how my code look like: static void copyFiles(SmbFile[] files, String

C# get file change events

大兔子大兔子 提交于 2020-01-21 21:52:26
问题 I do have a program which logs some specific events in a text file (it keeps the file open). Now I want to program a second application which shows these logs on a form. can I set an event for any change in a text file which is opened by another process? or I have to read that regularly? thanks 回答1: Have a look at the FileSystemWatcher Class 来源: https://stackoverflow.com/questions/3948542/c-sharp-get-file-change-events

PrintWriter not writing to file (Java)

旧街凉风 提交于 2020-01-21 18:56:06
问题 I am writing a kind of a cash machine program that will output the data into a file (Yes, I know its not in English, but that's not the point) and I am experiencing an error. When I try to use PrintWriter it doesn't work, I don't know why. public void writeFooter(List<Purchase> list) throws Exception{ int amountSold = 0; int amountNotSold = 0; int moneyRecieved = 0; openStreams(); printer.println("Проданные товары: "); for(int i = 0; i <= list.size() - 1;i++){ if(list.get(i).isSold()){

How to return millisecond information for File Access on Mac Os X (in Java)?

笑着哭i 提交于 2020-01-21 11:27:06
问题 I just recognized that Mac Os X does not return any millisecond information to java.io.File#lastModified() method. The long values are rounded, so the most specific kind of information is the second after transfer to a DateTime Object. Is there a way to get those information some other way, maybe through the java.nio.file.Files#readAttributes(Path,Class,LinkOption[]) method, or want it be possible to distinguish between milliseconds? 回答1: This is a limitation of the file system, not of the

AJAX reading from file

落爺英雄遲暮 提交于 2020-01-21 09:59:46
问题 I'm reading from a text file using AJAX. How do I read only the first line? 回答1: This code should help you read from a remote text file: var txtFile = new XMLHttpRequest(); txtFile.open("GET", "http://my.remote.url/myremotefile.txt", true); txtFile.onreadystatechange = function() { if (txtFile.readyState === 4) { // Makes sure the document is ready to parse. if (txtFile.status === 200) { // Makes sure it's found the file. allText = txtFile.responseText; lines = txtFile.responseText.split("\n"

How to use variables defined in a public class in other classes in java?

南笙酒味 提交于 2020-01-21 09:49:09
问题 A layman's question on the definition and use of variables: I need to make a Java GUI that gets user's input and stores it within a text file. However this writing has to be done inside an Actionlistener class (ie, user is clicking the button and text file is created and stored). This means that I have to define a variable in one class (public class) and use it in another (the one that defines the Actionlistener). How can I do this? Are global variables the only way? In my code I first define

工具导航Map