且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

打开Java实时写入文件

更新时间:2023-01-18 17:59:10

有趣:

让我们以简单的方式解决这个问题.

Lets deal this in simple way.

1. Save a file test.txt somewhere. 
2. Open that file and keep it opened

在Java中写入此文件(标准代码)

In Java write to this file (Standard Code)

FileWriter fw = new FileWriter(new FileOutputStream(new File("c:/test.txt")));
fw.write("ABC")

现在再次进入记事本文件.我通常使用Textpad,它会自动(通过警报)刷新,因为我们在后台更改了它(在您的情况下是通过Java).

Now go to notepad file again. I normally used Textpad it does refresh automatically (by an alert) because we changed it behind the scene (In your case through Java).

我希望可以澄清一下.

要想设法超出通用记事本exe的价格,就无法保证您将写入哪个文件.我不确定Windows如何处理该文件,因为您可以一次打开3个不同的文件,并且希望打开一个文件通过Java编写数据了吗?

To be fare trying to excess the genric notepad exe doesn't gurrantee which file you will write in. I am not sure how windows deal with it because you can open 3 different files at one time and which one you will expect to have your data written through java???