/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
public class Main
{
public static void main(String[] args) {
try {
String csvContent = "Name,Age,Location\nJohn,25,New York\nJane,30,San Francisco";
byte[] csvByteArray = createCsvByteArray(csvContent);
System.out.println(new String(csvByteArray, StandardCharsets.UTF_8));
// Send it to your desired API
} catch (IOException e) {
e.printStackTrace();
}
}
private static byte[] createCsvByteArray(String csvContent) throws IOException {
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
outputStream.write(csvContent.getBytes(StandardCharsets.UTF_8));
return outputStream.toByteArray();
}
}
}