写入我网站目录上的文件 - 代码正在执行但文件未更新

Writing to a File on my website directory - Code is executing but file is not updated

我正在写入我网站上的一个文件。我有权访问此文件。 下面是相同的方法代码: Eclipse 控制台上的最后输出是“3 完成写入文件”

但是,文件没有显示下面代码所做的更改
在 eclipse 控制台中没有错误和所有消息打印的情况下会发生什么?

public static void writetoDirFiles() {
URL url ;   
   try { 
        
        url = new URL("http://www.indisofttec.com/network_black_list.txt");   
        
        System.out.println("1 Opening Connection to the File"); 
        URLConnection yc = url.openConnection();    

        yc.addRequestProperty("User-Agent", "Mozilla");
        yc.setAllowUserInteraction(true);  
        yc.setDoOutput(true);  
        
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(
                                                       yc.getOutputStream()));  
        String fileContent = "window.io_global_name = 'BABLOO';";  
             
        System.out.println("2 Writing to the File"); 
       
        out.write(fileContent);      
        out.close();    
      
        System.out.println("3 Done Writing to the File");
       
   } catch (MalformedURLException e) {      
       e.printStackTrace(); 
   } catch (IOException e) {        
    e.printStackTrace();
   }          

代码正在将数据发送到 URL,如果服务器上没有处理它的代码,则忽略它。

如果您的代码在网站服务器上,您可以使用FileWriter class写入您网站内容的目录。

例如,假设 network_black_list.txt 在 /var/www/html:

try (BufferedWriter writer = new BufferedWriter(new FileWriter("/var/www/html/network_black_list.txt"))) {
    writer.write(fileContent);
} 

如果您的 Java 代码不在网站服务器上,您将需要使用文件传输解决方案,例如 FTP 或 SCP。