//*****************************************************************************
// Write to a file using Java "nio" package 
// Write entire file from a String                          
//*****************************************************************************
import java.nio.file.*;                             //import nio.file package

public class WriteFromString 
{
    public static void main(String[] args)
    { 
        String[] array = { "this is line 1",
                           "this is line 2",
                           "this is line 3" };
                           
        String str = String.join("\n", array);          //concatenate array elem into a long string

        try {            
            Path outfile = Path.of("/home/s/sultans/web/java/demo/8inpout/data/temp2.txt");

            Files.writeString(outfile, str);            //write entire string into file                                                     

//          Files.writeString(outfile, str, StandardOpenOption.APPEND);     //or .WRITE   
                                                                            //or .TRUNCATE_EXISTING
            System.out.println("Write Successful");
        } 
        catch(Exception e) 
        {
            e.printStackTrace();                        //print trace dump
        }        
    }
}