からAngularJSで、元のファイルとバイト配列をダウンロードし、 Javaサーバーは、サーバーからファイルを読み込むことで、以下の内容を送信しますコード:Javaの</p> <p>(それはPDF、DOCまたはイメージすることができます)私は、以下の要件を持っているサーバー
public static byte[] downloadFileAsStream(String fileName) throws IOException, MalformedURLException
File file = new File(fileName);
if (!file.exists()) {
// File not found
return null;
}
try {
InputStream inputStream = new BufferedInputStream(new FileInputStream(file));
return readFileAsByte(file.getAbsolutePath());
} catch (FileNotFoundException ex) {
ex.printStackTrace();
}
return null;
}
private static byte[] readFileAsByte(String filePath) {
try {
Path path = Paths.get(filePath);
return Files.readAllBytes(path);
} catch (IOException ex) {
ex.printStackTrace();
}
return new byte[0];
}
サーバは、これは元のファイルAngularJSとして変換する必要があり、次のコードは、に基づいて、クライアント側のファイルを作成するために使用することができる