java-io

How to write data to a file through java?

不打扰是莪最后的温柔 提交于 2019-12-13 06:29:50
问题 I want to make a GUI application that contains three functions as follows: Add a record Edit a record Delete a record A record contains two fields - Name and Profession There are two restrictions for the application You can't use database to store info. You have to use a flat file. Total file should not be re-written for every add/delete operation. So, my questions are mentioned below: Q1. Which file format would be better? (.xml or .csv or .txt or any other) Q2. How can we perform the add

How to import lwjgl_util

可紊 提交于 2019-12-13 05:18:47
问题 I am trying to make a 3d lwjgl object, and have done so, but am getting an error telling me that I don't have the XPMFile. So I did some research, and have found that I need to load the XPMFile, but can't seem to find out how to do so. So I am wondering how to load the XPMFile for lwjgl_Util. **EDIT* * Ok, I've decided to change the question to fit what I know now. The new Question is: How do you import lwjgl_util, so that you don't get the XPMFile error??? 回答1: have you put lwjgl_util.jar on

Read logcat from app not working correctly

自作多情 提交于 2019-12-13 04:06:25
问题 I am trying to read from the logcat output in my app. I am able to read in correctly, but it goes on reading it in endless loop. Somehow there seems no way to detect the end of stream. Not sure what I am doing wrong. Here is my code: String baseCommand = "logcat -v time MyTag:D *:S"; Process process = null; try { process = Runtime.getRuntime().exec(baseCommand); InputStreamReader reader = new InputStreamReader(process.getInputStream()); BufferedReader bufferedReader = new BufferedReader

Is put-ing to a ByteBuffer then writing it to a file more efficient than writing the individual field

Deadly 提交于 2019-12-13 03:37:04
问题 I want to write ONLY the values of the data members of an object into a file, so here I can can't use serialization since it writes a whole lot other information which i don't need. Here's is what I have implemented in two ways. One using byte buffer and other without using it. Without using ByteBuffer: 1st method public class DemoSecond { byte characterData; byte shortData; byte[] integerData; byte[] stringData; public DemoSecond(byte characterData, byte shortData, byte[] integerData, byte[]

Can't Read *.ttf File

孤者浪人 提交于 2019-12-13 00:14:11
问题 I'm programming a dictionary for a language I'm creating. The language does not use any English letters, so I created my own font using free online software at http://www.myscriptfont.com/, which would hopefully allow me to use my language's symbols. The first step to make this dictionary would then be to import this custom font, but it's not working. Here's the part of the code where I import it: /** * Constructor for class Bank */ public Bank() throws Exception { //Previous code creates

Multipart transferTo looks for a wrong file address when using createTempFile

自古美人都是妖i 提交于 2019-12-12 19:13:42
问题 I have the following java code in Spring framework to convert a multipart file to a regular file: public static File convertToFile(MultipartFile multipart) { File convFile = null; try { convFile = File.createTempFile(multipart.getOriginalFilename(), ""); multipart.transferTo(convFile); } catch (IllegalStateException | IOException e) { } return convFile; } I can see the file when I check the place where this temporary file is created, but the file size is 0, there is no content for it. Why

Axis2 File Upload by chunk

血红的双手。 提交于 2019-12-12 12:40:40
问题 I'm trying to upload file using Axis2 web service by 1024 chunk size. My server side looks like this: public void appendChunk(int count, byte[] buffer){ FileOutputStream fos = null; try { File destinationFile = new File("c:\\file1.exe"); fos = new FileOutputStream(destinationFile,true); fos.write(buffer,0, count); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally{ try { fos.close(); } catch (IOException e) { e.printStackTrace();

How can i zip files in Java and not include files paths

﹥>﹥吖頭↗ 提交于 2019-12-12 07:24:52
问题 For example, I want to zip a file stored in /Users/me/Desktop/image.jpg I made this method: public static Boolean generateZipFile(ArrayList<String> sourcesFilenames, String destinationDir, String zipFilename){ // Create a buffer for reading the files byte[] buf = new byte[1024]; try { // VER SI HAY QUE CREAR EL ROOT PATH boolean result = (new File(destinationDir)).mkdirs(); String zipFullFilename = destinationDir + "/" + zipFilename ; System.out.println(result); // Create the ZIP file

Reading a binary file into ArrayList in Java

≡放荡痞女 提交于 2019-12-12 06:12:17
问题 I want to read binary file in java. I have 153(1.bin, 2.bin...153.bin) bin file. I must read that. I thought that I must use ArrayList for buffering. But I could not do that. How can I do this ? After some research, I found that way in this title(Reading a binary input stream into a single byte array in Java). There is code like below in this title. StringBuilder sb = new StringBuilder(); String fileName = "/path/10.bin"; byte[] buffer; try { buffer = Files.readAllBytes(Paths.get(fileName));

How to get an instance of java.lang.Class from a .class file?

爱⌒轻易说出口 提交于 2019-12-12 05:06:19
问题 My question is how to get an instance of java.lang.Class from a given .class file? So if I have the file MyClass.class, and the corresponding java.io.File instance, how can I use this to get an instance of java.lang.Class that corresponds to MyClass? 回答1: Class<?> clazz = new URLClassLoader(new File("").toURL()).loadClass(className); 回答2: You actually need a classloader to do this (to turn a byte-code byte-stream into a class). There a few options here. One, you use a standard URLClassLoader