java-io

Does new File(“…”) lock the file?

寵の児 提交于 2020-01-04 02:50:06
问题 I read that new File("path") doesn't physically create a file on disk. Though in the API it is said: Instances of this class may or may not denote an actual file-system object such as a file or a directory. If it does denote such an object then that object resides in a partition. A partition is an operating system-specific portion of storage for a file system. A single storage device (e.g. a physical disk-drive, flash memory, CD-ROM) may contain multiple partitions. So I'm curious if it is

Array classes with serialVersionUID?

↘锁芯ラ 提交于 2020-01-02 23:12:12
问题 I am having trouble understanding this comment from the Java serialization documentation: Array classes cannot declare an explicit serialVersionUID, so they always have the default computed value, but the requirement for matching serialVersionUID values is waived for array classes. Maybe I am unable to understand the obvious, however, I haven't figured why would I need to do this? 回答1: I think that the answer to your question is to read up on serialVersionUID. In particular, you often want to

Why does usage of java.nio.files.File::list is causing this breadth-first file traversal program to crash with the “Too many open files” error?

为君一笑 提交于 2020-01-02 07:05:56
问题 Assumption: Stream s are lazy, hence the following statement does not load the entire children of the directory referenced by the path into memory; instead it loads them one by one, and after each invocation of forEach , the directory referenced by p is eligible for garbage collection, so its file descriptor should also become closed: Files.list(path).forEach(p -> absoluteFileNameQueue.add( p.toAbsolutePath().toString() ) ); Based on this assumption, I have implemented a breadth-first file

Read file and write file which has characters in UTF - 8 (different language)

社会主义新天地 提交于 2020-01-02 03:17:07
问题 I have a file which has characters like: " Joh 1:1 ஆதியிலே வார்த்தை இருந்தது, அந்த வார்த்தை தேவனிடத்திலிருந்தது, அந்த வார்த்தை தேவனாயிருந்தது. " www.unicode.org/charts/PDF/U0B80.pdf‎ When I use the following code: bufferedWriter = new BufferedWriter (new OutputStreamWriter(System.out, "UTF8")); The output is boxes and other weird characters like this: "�P�^����O֛���;�<�aYՠ؛" Can anyone help? these are the complete codes: File f=new File("E:\\bible.docx"); Reader decoded=new InputStreamReader

to edit a specific line in a textfile using java program

≯℡__Kan透↙ 提交于 2020-01-01 17:30:11
问题 Ok, say I have a text file called "people.txt", and it contains the following information: 1 adam 20 M 2 betty 49 F 3 charles 9 M 4 david 22 M 5 ethan 41 M 6 faith 23 F 7 greg 22 M 8 heidi 63 F Basically, the first number is the ID of the person, then comes the person's name, age and gender. Say I want to replace line 2, or the person with ID number 2 with different values. Now, I know I cant use RandomAccessFile for this because the names are not always the same number of bytes, neither are

java.io.FileNotFoundException on an existing file

大城市里の小女人 提交于 2020-01-01 05:16:12
问题 I am getting this error when I try to open a file: java.io.FileNotFoundException: D:\Portable%20Programs\Android%20Development\workspace3\XXX-desktop\bin\World_X.fr (The system cannot find the path specified) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.<init>(Unknown Source) at java.util.Scanner.<init>(Unknown Source) The file is existing in the directory but I am still getting this error. However when I copy the same file in the Eclipse workspace Project src

Can i stop the malicious reading the class files via “java.io” function,with NATIVE code(tool)?

只愿长相守 提交于 2019-12-31 07:34:13
问题 we'd defend against the code crackers who can operate on the whole operation system who may read the encoded class-file via "java.io" and save the copy we'd protect java-based application's intellectual property this requirement was raised by several customers, so it has realistic value. Simplex Java-JDK-JVM solution like securityManager without native code/tool can NOT be accepted because it's easy to be bypassed, since cracker have the admin privilege on the OS in this scenario. 回答1: You

Infinite loop on Scanner.hasNext, reading from a file

流过昼夜 提交于 2019-12-31 02:54:12
问题 I'm apparently facing an infinite loop on while(input.hasNext()) , as in following code File file = new File("data.txt"); Scanner input = new Scanner(file); int sum = 0; while (input.hasNext()) { if (input.hasNextInt()) { sum += input.nextInt(); } } System.out.println(sum); Some related questions explain why it always returns true if input stream is System.in , however I'm scanning through a File . Please let me know where I'm going wrong. I'm attempting to calculate the sum of unique integer

How to pipe InputStream to ProcessBuilder

假装没事ソ 提交于 2019-12-30 04:37:25
问题 Please move down to the 2nd update. I didn't want to change the previous context of this question. I'm using wkhtmltoimage from a Java app. The standard way of using it is - path-to-exe http://url.com/ image.png . According to their docs, if we write a - instead of an input URL, the input shifts to STDIN. I'm starting the process using ProcessBuilder - ProcessBuilder pb = new ProcessBuilder(exe_path, " - ", image_save_path); Process process = pb.start(); Now I'm unable to figure out how to

DataInputStream.read() vs DataInputStream.readFully()

心已入冬 提交于 2019-12-29 06:52:20
问题 Im making a simple TCP/IP Socket app Whats the different between doing this: DataInputStream in = new DataInputStream(clientSocket.getInputStream()); byte[] buffer = new byte[100]; in.readFully(buffer); versus doing this: DataInputStream in = new DataInputStream(clientSocket.getInputStream()); byte[] buffer = new byte[100]; in.read(buffer); I had a look at the documentation, they have the same exact description. readFully() and read() So can I assume its the same thing? 回答1: The Javadoc for