如何以编程方式使系统创建交换文件?

发布于 12-23 12:10 字数 303 浏览 5 评论 0原文

如果您必须以编程方式让系统为您创建交换文件,您会怎么做?

我并不打算实际创建交换文件,而是正在调试自己的代码中的一个问题,试图更好地理解我做错了什么,导致系统创建交换文件。

我的程序(毫无疑问你已经猜到了)正在对文件进行大量读取和写入(从文件 A 中提取一些数据并将其写入文件 B)

什么会导致发生这样的事情?

更新:

  • 请注意创建的交换文件大小为 0 字节。
  • 程序用Java编写并在Linux上运行

If you had to programmatically have system create swap files for you, how would you do it?

I am not looking to actually create swap file, but am debugging an issue in own code trying to better understand what did i do wrong that would cause system to create the swap files.

My program (as no doubt you have guessed) is doing a lot of reading and writing of files (extract some data from file A and write it to file B)

What would cause something like this to happen?

UPDATE:

  • Please note swap files created are 0 bytes in size.
  • Program is written in Java and runs on Linux

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

水晶透心2024-12-30 12:10:36

Vim 或 Gvim 创建 .swp 文件。也许您有一个调用 Vim 的脚本?我从未在脚本中调用过 vim,但是 这是一个关于这样做的问题,所以我很确定这是可能的。

Vim or Gvim creates .swp files. Maybe you have a script that invokes Vim? I've never invoked vim in a script, but this is a question about doing that, so I'm pretty sure it's possible.

北城孤痞2024-12-30 12:10:36

交换文件适用于程序使用的内存多于 RAM 中的可用内存的情况。要使系统写入交换区,您只需要使用大量内存即可。您可以通过分配大量内存块来做到这一点。

Swap files are for those times when programs use more memory than is available in RAM. To make the system write to swap you just have to use up a lot of memory. You could do that by allocating a lot of blocks of memory.

So尛奶瓶2024-12-30 12:10:36

事实证明,问题的出现是由于我在读取/写入文件后不正确地关闭 IO 连接。

一旦我

finally {
    try {
        in.close();
        fstream.close();
        br.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

停止创建交换文件并且问题得到解决。

As it turns out, the problem came about due to me improperly closing IO connections once files has been read/ written to.

Once i

finally {
    try {
        in.close();
        fstream.close();
        br.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

Swap files stopped being created and issue was resolved.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文