English 中文(简体)
我如何在 Java某个具体地点归还档案?
原标题:How do I return a file at a specific location in Java?
  • 时间:2012-01-12 16:50:38
  •  标签:
  • java
  • file

我目前正在利用一个外部图书馆功能,把一个档案物体归还。 这对把档案放在一个缺省地点,但为了容纳同时使用的用户,我需要把档案放在一个具体的文件夹中。 如果没有能够改变档案的功能,是否有文件功能,让我具体说明它会去什么?

最佳回答

页: 1 To(目的地),载于File的AP,将存放于另一条抽象途径的档案重新命名。

页: 1

import java.io.File;

public class MainClass {

  public static void main(String args[]) {

    try {

      File oldFile = new File("/usr/bin/temp/");

      File newFile = new File("/usr/bin/hunter/temp");

      boolean result = oldFile.renameTo(newFile);

      System.out.println(result);
    } 
    catch (Exception e) 
    {
      e.printStackTrace();
    }

并且注意到,APICA表示,并不总是保证成功,因此,在你使用这种方法时,必须检查这种方法的回报价值。

问题回答

首先使用<代码>File.renameTo()将其移至指定地点。

我认为,你必须在你想要的地点建立一个新的<代码>File,然后使用<代码>FileInputStream,在您的原始<代码>File和FileOutputStream上读,以写到你想要的地点。

如果我正确记得,File.rename

如果只有 Java让你这样做,你就可以改变工作名录。 既然如此,如果你收到已经制作的档案,你仍然可以使用File.rename To()。

没有,你需要做一些事情来改变档案,搬回档案,建立工作目录等等。 后两个问题仍然可以提出问题,但取决于如何确定评估。

如果您能了解你可以采用的方法。

The java.io.File object is simply an abstract representation of a file or directory pathname, i.e., it s just the file s name and location, not the actual file. Not knowing that library you re using, i don t know if it already created the file, and is simply telling you where it is (i think this is likely), or if it s telling you where to create the file. But it s likely that the answer you re looking for doesn t involve manipulating this File object, but doing something differently with the library to determine where the file will go.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...