file-io

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

PrintWriter add text to file

微笑、不失礼 提交于 2020-01-21 08:51:14
问题 In my online computer science class I have to write a program to determine the surface gravity on each planet in the solar system. I have gotten almost every aspect of it to work save one. I need to write the surface gravity to a file using a separate method. This is my current method: public static void writeResultsToFile(double g) throws IOException{ PrintWriter outFile = new PrintWriter(new File("planetaryData.txt")); outFile.printf("%.2f%n", g); outFile.close(); } My problem is that when

PrintWriter add text to file

两盒软妹~` 提交于 2020-01-21 08:51:06
问题 In my online computer science class I have to write a program to determine the surface gravity on each planet in the solar system. I have gotten almost every aspect of it to work save one. I need to write the surface gravity to a file using a separate method. This is my current method: public static void writeResultsToFile(double g) throws IOException{ PrintWriter outFile = new PrintWriter(new File("planetaryData.txt")); outFile.printf("%.2f%n", g); outFile.close(); } My problem is that when

how to update the contain in .txt file java [closed]

…衆ロ難τιáo~ 提交于 2020-01-21 08:32:00
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . for example i have the file named file.txt which contain personal information (id,name, salary): A123 Anna 3000 A234 Alex 4000 A986 Jame 5000 How can I write a java code that allow user to enter an ID of a person