java-io

Java- export to jar- i/o problems

最后都变了- 提交于 2019-12-19 12:36:06
问题 I work on Eclipse (Juno with JDK7), and the program runs (on Eclipse) fine. My problematic lines are: URL imageURL = new URL("http://www.idautomation.com/ocr-a-and-ocr-b-fonts/new_sizes_ocr.png"); RenderedImage img = ImageIO.read(imageURL); File outputfile = new File("saved.png"); ImageIO.write(img, "png", outputfile); But when i export the project to a jar file and try to run it via windows (7- 64 bit) command line, the following error appears: Exception in thread "main" java.lang.reflect

Java- export to jar- i/o problems

两盒软妹~` 提交于 2019-12-19 12:33:42
问题 I work on Eclipse (Juno with JDK7), and the program runs (on Eclipse) fine. My problematic lines are: URL imageURL = new URL("http://www.idautomation.com/ocr-a-and-ocr-b-fonts/new_sizes_ocr.png"); RenderedImage img = ImageIO.read(imageURL); File outputfile = new File("saved.png"); ImageIO.write(img, "png", outputfile); But when i export the project to a jar file and try to run it via windows (7- 64 bit) command line, the following error appears: Exception in thread "main" java.lang.reflect

Java- export to jar- i/o problems

落爺英雄遲暮 提交于 2019-12-19 12:33:41
问题 I work on Eclipse (Juno with JDK7), and the program runs (on Eclipse) fine. My problematic lines are: URL imageURL = new URL("http://www.idautomation.com/ocr-a-and-ocr-b-fonts/new_sizes_ocr.png"); RenderedImage img = ImageIO.read(imageURL); File outputfile = new File("saved.png"); ImageIO.write(img, "png", outputfile); But when i export the project to a jar file and try to run it via windows (7- 64 bit) command line, the following error appears: Exception in thread "main" java.lang.reflect

Sockets: BufferedReader readLine() blocks

好久不见. 提交于 2019-12-18 15:12:13
问题 I am using BufferedReader.readLine() method to read a response from a remote server (which is written in C and I have no access to source code). BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; while((line = br.readLine())!=null){ [...] } But it always blocks at the last line until it times out. So I used the following code: int b; while(true){ b = in.read; [...] } and I found out that the last byte read has an integer value of 13, which I think it is a carriage

how to create a file with world readable permission under subdirectory of files directory

做~自己de王妃 提交于 2019-12-18 11:47:44
问题 I need to create files under myapp/files/subdir with global permission in my application. I do this because I use external applications to open some files Using this FileOutputStream fos = openFileOutput(FILENAME, Context.MODE_WORLD_READABLE); creates file only under files folder. Using File dir=new File(Constants.TASK_DIRECTORY); dir.mkdirs(); File file=new File(dir, FILENAME); file.createNewFile(); FileOutputStream fos=new FileOutputStream(file); creates files under subdirectories but with

Using Java's File.delete() method

烂漫一生 提交于 2019-12-18 09:21:34
问题 When I used the File.delete() method to delete a file, where is the deleted file? I am using a Mac and I don't see the file in the Trash. I want to know where the file is being stored at? Or if it is permanently gone. Thanks, 回答1: It's gone. The trash bin is just a temporary place where files are put before being deleted, when you "delete" them through the OS. In most filesystems, however, deleting a file only removes the pointer to it from the system's list of files. The actual data may sit

Modify a hidden file in Java

旧城冷巷雨未停 提交于 2019-12-18 08:47:34
问题 I have a file that user downloads and then I execute a command within java to hide the file: Runtime.getRuntime().exec("attrib +H myFile.txt"); Now later I need to access that hidden file but I'm getting java.io.FileNotFoundException: myFile.txt (Access is denied) This works if file is not hidden, but the file needs to be hidden so user wont modify it. So how am I supposed to modify the hidden file? Is there any way to do this in Java? Thanks for your ideas. 回答1: I agree with Dolph, however

Java read file got a leading BOM [  ]

喜欢而已 提交于 2019-12-18 08:31:38
问题 I am reading a file containing keywords line by line and found a strange problem. I hope lines that following each other if their contents are the same, they should be handled only once. Like sony sony only the first one is getting processed. but the problems is, java doesn't treat them as equals. INFO: [, s, o, n, y] INFO: [s, o, n, y] My code looks like the following, where's the problem? FileReader fileReader = new FileReader("some_file.txt"); BufferedReader bufferedReader = new

Java read file got a leading BOM [  ]

北慕城南 提交于 2019-12-18 08:31:10
问题 I am reading a file containing keywords line by line and found a strange problem. I hope lines that following each other if their contents are the same, they should be handled only once. Like sony sony only the first one is getting processed. but the problems is, java doesn't treat them as equals. INFO: [, s, o, n, y] INFO: [s, o, n, y] My code looks like the following, where's the problem? FileReader fileReader = new FileReader("some_file.txt"); BufferedReader bufferedReader = new

Use of FilenameFilter

可紊 提交于 2019-12-18 03:12:23
问题 I have a directory: File dir = new File(MY_PATH); I would like to list all the files whose name is indicated as integer numbers strings, e.g. "10", "20". I know I should use: dir.list(FilenameFilter filter); How to define my FilenameFilter ? P.S. I mean the file name could be any integer string, e.g. "10" or "2000000" or "3452345". No restriction in the number of digits as long as the file name is a integer string. 回答1: You should override accept in the interface FilenameFilter and make sure