'function to save in a external file

I have a java class that performs the replace of a certain part of a url, with the elements contained in a vector, I would need the replace results to be saved in an external file

import java.net.MalformedURLException;
import java.net.URL;

public class Registra {
public  static void main (String args []) {

    String indirizzo = "https://www.sito.it//GenericLeaveGame?PARTECIPATION_ID=@@@part_id&KT=1";
    URL u = null;

    int[] ticket = new int[100] ;
    char N5357275F8B8CENN = 0;
    char N535827614F962SG = 1;
    ticket [0] = N5357275F8B8CENN;
    ticket [1] = N535827614F962SG;

    try
    {
        u = new URL(indirizzo);
        System.out.println("URL aperto: " + u);
    }
    catch (MalformedURLException e)
    {
        System.out.println("URL errato: " + u);
    }



    }


}


Solution 1:[1]

there are many ways to write strings to files in java , one of them to use BufferedWriter with FileWriter

example function can be like :

    public static void writeToFile(String fileName, String outPut)
            throws IOException {
        BufferedWriter writer = new BufferedWriter(new FileWriter(fileName));
        writer.write(outPut);

        writer.close();
    }

and you can call this function , like :

        try {
            writeToFile("outPutFilw.txt","strings or url to write in the file");
        } catch (IOException e) {
            e.printStackTrace();
        }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 M AboEl-Soud