Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
394 views
in Technique[技术] by (71.8m points)

java - 在Java中,有什么方法可以用记事本打开非txt格式的文件(In java, is there any way i can open file which is not txt format with notepad)

In this source code, I'm trying to open hosts file with notepad.

(在此源代码中,我试图使用记事本打开hosts文件。)

Is there any way that i can try??

(有什么办法可以尝试吗?)

**hosts file is not in txt format.

(**主机文件不是txt格式。)

this program is to add "youtube.com 127.0.0.1" in hosts file so that i can ban youtube in my computer

(该程序是在主机文件中添加“ youtube.com 127.0.0.1”,以便我可以在计算机中禁止YouTube)

//youtube ban
import java.awt.Desktop;
import java.io.*;
public class main
{
    public static void main(String[] args)
{
    try
    {

        File file = new File("C:\windows\System32\drivers\etc\hosts");
        File file2 = new File("C:\Users\junes\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Accessories\Notepad");
        if(!Desktop.isDesktopSupported())
        {
            System.out.println("not supported");
            return;
        }
        Desktop desktop = Desktop.getDesktop();
        if(file.exists())
            desktop.open(file );
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }
}

}

(})

  ask by BurdinCake translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...