java-io

stitch images together in java

我是研究僧i 提交于 2019-12-06 05:18:23
I'm trying to stitch some images together using java. I have a bunch of images I'd like to stitch together and they are all the same dimensions so it's really just a question of lining them up next to each other I suppose. I have it working but it's very slow and probably very memory intensive. I'm wondering if there's an easier way: public static void main(String[] args) throws IOException { int dim = 256; BufferedImage merged = null; for(int y = 0; y<10;y++) { for(int x = 0; x<10;x++) { URL url = new URL(someURL); BufferedImage nextImage = ImageIO.read(url); if(merged==null) merged=nextImage

Apache hive error Merging of credentials not supported in this version of hadoop

邮差的信 提交于 2019-12-06 03:58:30
问题 I am using hadoop 1.2.1, hbase 0.94.14 and hive 1.0.0. There are three datanodes in my clsuter and three regionservers also. I have to import some data from hbase to hive. I have configured hive successfully but when I ran a command to count no. of rows in hive table, its gives following ERROR [main]: exec.Task (SessionState.java:printError(833)) - Job Submission failed with exception 'java.lang.RuntimeException(java.io.IOException: Merging of credentials not supported in this version of

Inappropriate ioctl for device from FileOutputStream.close()

空扰寡人 提交于 2019-12-06 01:41:12
I have some code that saves some preferences to file using FileOutputStream . It is standard code I've written a thousand times: FileOutputStream out = new FileOutputStream(file); try { BufferedOutputStream bos = new BufferedOutputStream(out); try { store(bos, comments); } finally { bos.close(); } } finally { out.close(); } One of our users is reporting the following error on Linux during the close() call. java.io.IOException: Inappropriate ioctl for device at java.io.FileOutputStream.close0(Native Method) at java.io.FileOutputStream.close(FileOutputStream.java:341) at java.io

java : writing large files?

假如想象 提交于 2019-12-06 00:34:56
问题 Greetings , I get huge number of records from database and write into a file.I was wondering what the best way to write huge files. (1Gb - 10Gb). Currently I am using BufferedWriter BufferedWriter mbrWriter=new BufferedWriter(new FileWriter(memberCSV)); while(done){ //do writings } mbrWriter.close(); 回答1: If you really insist using Java for this, then the best way would be to write immediately as soon as the data comes in and thus not to collect all the data from ResultSet into Java's memory

File.mkdir() and mkdirs() are creating file instead of directory

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-05 23:15:21
问题 I use the following code: final File newFile = new File("/mnt/sdcard/test/"); newFile.mkdir(); // if I use mkdirs() result is the same And it creates an empty file! Why? 回答1: You wouldn't use mkdirs() unless you wanted each of those folders in the structure to be created. Try not adding the extra slash on the end of your string and see if that works. For example final File newFile = new File("/mnt/sdcard/test"); newFile.mkdir(); 回答2: When I need to ensure that all dirs for a file exist, but I

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?

落爺英雄遲暮 提交于 2019-12-05 21:16:01
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 traversal tool: public class FileSystemTraverser { public void traverse(String path) throws IOException {

Why is my program denying access to create a file?

泄露秘密 提交于 2019-12-05 15:46:40
In the book I'm reading on Java, it demonstrates serialization by using a program that writes to a file and stores it away. I'm getting a strange error that I don't know how to read and it denies me access to creating a .txt file. Here's the error: Exception in thread "main" java.io.FileNotFoundException: C:\testFile.txt (Access is denied) at java.io.FileOutputStream.open(Native Method) at java.io.FileOutputStream.<init>(Unknown Source) at java.io.FileOutputStream.<init>(Unknown Source) at serializableTests.MyProgram.main(MyProgram.java:18) Here's the two classes for the program: User class:

About File file = new File(path)

房东的猫 提交于 2019-12-05 14:39:37
The Java.iO.File document says the following words about its constructor which takes the pathname : public File(String pathname) Creates a new File instance by converting the given pathname string into an abstract pathname. If the given string is the empty string, then the result is the empty abstract pathname. But what if the pathname points to a file which is already existing ? File file = new File(PATH_TO_AN_EXISTING_FILE); Does the above file instance represent a fresh new file (with the existing one be deleted?) Or does it represent the existing file ? What the documentation says is that

java.nio.file.FileAlreadyExistsException how to resolve this in java7

时光总嘲笑我的痴心妄想 提交于 2019-12-05 12:21:12
i am writing a code i am creating a directory with java nio api my segment of code is Path target = Paths.get(""+folder_path+xx[0]); Set<PosixFilePermission> perms = null; if(xx[2].toLowerCase().equals("read")) perms =PosixFilePermissions.fromString("r--------"); if(xx[2].toLowerCase().equals("read/write")) { perms =PosixFilePermissions.fromString("rw-------"); } FileAttribute<Set<PosixFilePermission>> attr = PosixFilePermissions.asFileAttribute(perms); Files.createDirectory(target, attr); but it is throwing an error java.nio.file.FileAlreadyExistsException: /home/ritesh/Desktop/userA reason i

Java I/O - Simulate input for System.console()

Deadly 提交于 2019-12-05 12:12:53
I am writing a JUnit for a program created in an exercise. That means the test needs to cover as many cases as possible and I don't have any influence on how certain things in the program are implemented. Also, the program runs an infinite loop where at one point, it requires the user to input something. For the JUnit test I run the program in another Thread and simulate the user input from within the JUnit Thread . So far, everything works fine if the program reads the user input from System.in , because this stream can easily replaced. But there's also the possiblity that the program