Tag: java io

使用serialVersionUID的数组类?

我无法理解Java序列化文档中的这条评论: 数组类不能声明显式的serialVersionUID,因此它们始终具有默认的计算值,但是对于数组类,不需要匹配serialVersionUID值。 也许我无法理解这一点,但是,我还没想到为什么我需要这样做呢?

如何在Java中将zip文件移动到blob列?

我有一个Java程序,它创建了许多xml文件,然后将它们压缩并将它们保存到文件系统中。 稍后在程序中我想将相同的zip文件放入我的oracle数据库的blob列中。 问题是我不知道该怎么做。 我不需要阅读它或对数据做任何事情,只需将其移动到数据库以进行持久的中央存储。 谢谢!

使用ASCII线处理Java IO的最快方法

我正在通过Socket使用ASCII输入/输出流,速度至关重要。 我听说使用正确的Java技术确实有所作为。 我有一本教科书说使用Buffers是最好的方法,但也建议使用DataInputStreamReader进行链接。 对于输出我使用带有OutputStreamWriter的BufferedOutputStream似乎没问题。 但我不确定输入流的用途。 我正在开发新系列,扫描仪有用吗? 速度至关重要,我需要尽快从网络上获取数据。 谢谢。 PH

Spring Mvc java.io.FileNotFoundException – ApplicationContext.xml

applicationContext.xml在WEB-INF文件夹中,为什么我收到此错误: org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [applicationContext.xml]; nested exception is java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not exist 在web.xml org.springframework.web.context.ContextLoaderListener log4jConfigLocation /WEB-INF/classes/log4j.properties org.springframework.web.util.Log4jConfigListener org.springframework.web.context.ContextLoaderListener crimetrack org.springframework.web.servlet.DispatcherServlet 1 crimetrack *.htm index.jsp /spring /WEB-INF/tld/spring-form.tld

在java中将图像拼接在一起

我正在尝试使用java将一些图像拼接在一起。 我有一堆图像,我想拼接在一起,它们都是相同的尺寸所以它实际上只是一个问题,我想它们将它们排列在一起。 我有它的工作,但它很慢,可能非常耗费内存。 我想知道是否有更简单的方法: 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; else { BufferedImage tempMerged; tempMerged = new BufferedImage(10*dim,10*dim,merged.getType()); //Write first image for(int […]

在服务器上创建Zip文件并使用java下载该zip文件

我有以下代码从mkyong到本地的zip文件。 但是,我的要求是在服务器上压缩文件并需要下载。 可以任何人帮助。 代码写入zipFiles: public void zipFiles(File contentFile, File navFile) { byte[] buffer = new byte[1024]; try{ // i dont have idea on what to give here in fileoutputstream FileOutputStream fos = new FileOutputStream(“C:\\MyFile.zip”); ZipOutputStream zos = new ZipOutputStream(fos); ZipEntry ze= new ZipEntry(contentFile.toString()); zos.putNextEntry(ze); FileInputStream in = new FileInputStream(contentFile.toString()); int len; while ((len = in.read(buffer)) […]

java.nio.file.FileAlreadyExistsException如何在java7中解决这个问题

我正在编写代码我正在用java nio api创建一个目录,我的代码段是 Path target = Paths.get(“”+folder_path+xx[0]); Set 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> attr = PosixFilePermissions.asFileAttribute(perms); Files.createDirectory(target, attr); 但这是一个错误 java.nio.file.FileAlreadyExistsException: /home/ritesh/Desktop/userA 我知道的原因是因为一个目录已经具有相同的名称,但我想用我的代码目录生成的目录覆盖userA目录如何完成这个?

只有在完全写入和关闭后才能从HDFS读取文件

我有两个进程在运行。 一种是将文件写入HDFS,另一种是加载这些文件。 第一个进程(写入文件的进程)正在使用: private void writeFileToHdfs(byte[] sourceStream, Path outFilePath) { FSDataOutputStream out = null; try { // create the file out = getFileSystem().create(outFilePath); out.write(sourceStream); } catch (Exception e) { LOG.error(“Error while trying to write a file to hdfs”, e); } finally { try { if (null != out) out.close(); } catch (IOException e) { LOG.error(“Could […]

可以将apache FileUtils.writeLines()附加到文件(如果存在)

公共文件FileUtils看起来很酷,我无法相信它们不能被附加到文件中。 File file = new File(path); FileUtils.writeLines(file, printStats(new DateTime(), headerRequired)); 以上只是每次都替换文件的内容,我只想继续标记这些东西,就像这段代码一样。 fw = new FileWriter(file, true); try{ for(String line : printStats(new DateTime(), headerRequired)){ fw.write(line + “\n”); } } finally{ fw.close(); } 我搜索了javadoc,却一无所获! 我错过了什么?

确保在JVM出口上删除文件

File.deleteOnExit()是否保证即使JVM过早被杀死也会删除该文件?