Я пытаюсь загрузить файл Excel с сайта Share Point. Я могу загрузить файл в свою локальную систему из приложения SharePoint. но когда я пытаюсь открыть загруженный файл Excel, он говорит, что файл поврежден, и его невозможно открыть. а также размер файла увеличивался при загрузке.
Я использую код, как показано ниже.
// Fetch file content as InputStream
InputStream inputStream = graphClient
.sites(siteId)
.drives(driveId)
.root()
.itemWithPath(filePath)
.content()
.buildRequest()
.get();
if (inputStream == null) {
throw new Exception("Failed to fetch file content from SharePoint.");
}
// Read InputStream into byte array
byte[] fileBytes = inputStream.readAllBytes();
logger.info("Downloaded " + fileBytes.length + " bytes.");
// Save the byte array as a file
Path destinationPath = Paths.get(localFilePath);
try (FileOutputStream fos = new FileOutputStream(destinationPath.toFile())) {
fos.write(fileBytes);
logger.info("File saved to " + localFilePath);
} catch (IOException e) {
logger.severe("Error saving the file: " + e.getMessage());
throw e;
}
а также я пробовал использовать байты, такие как код belwo.
try {
BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(downloadPath.toFile()));
//FileOutputStream outputStream = new FileOutputStream(downloadPath.toFile());
byte[] buffer = new byte[16 * 1024]; // Buffer size (8 KB)
int bytesRead;
while ((bytesRead = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
totalBytesRead += bytesRead;
}
outputStream.flush();
logger.info("File downloaded successfully to: " + downloadPath.toString());
} catch (IOException e) {
logger.error("Error while saving the file to disk: " + e.getMessage(), e);
}
помогите пожалуйста в этом вопросе, есть ли другой способ скачать файл. Основная проблема: я не могу открывать файлы, такие как Excel и PDF.
Я также попробовал код ниже
try {
BufferedInputStream bis = new BufferedInputStream(inputStream);
BufferedOutputStream bos = new BufferedOutputStream(Files.newOutputStream(downloadPath, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING));
BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(downloadPath.toFile()));
byte[] dataBuffer = new byte[1024];
int bytesRead;
while ((bytesRead = bis.read(dataBuffer, 0, 1024)) != -1) {
bos.write(dataBuffer, 0, bytesRead);
}
outputStream.flush();
logger.info("File downloaded successfully to: " + downloadPath.toString());
} catch (IOException e) {
logger.error("Error while saving the file to disk: " + e.getMessage(), e);
}
Подробнее здесь: https://stackoverflow.com/questions/791 ... sharepoint
Столкнулся с проблемой с поврежденным файлом (Excel) после загрузки из SharePoint с использованием Java-кода Graph API ⇐ JAVA
Программисты JAVA общаются здесь
1731074978
Anonymous
Я пытаюсь загрузить файл Excel с сайта Share Point. Я могу загрузить файл в свою локальную систему из приложения SharePoint. но когда я пытаюсь открыть загруженный файл Excel, он говорит, что файл поврежден, и его невозможно открыть. а также размер файла увеличивался при загрузке.
Я использую код, как показано ниже.
// Fetch file content as InputStream
InputStream inputStream = graphClient
.sites(siteId)
.drives(driveId)
.root()
.itemWithPath(filePath)
.content()
.buildRequest()
.get();
if (inputStream == null) {
throw new Exception("Failed to fetch file content from SharePoint.");
}
// Read InputStream into byte array
byte[] fileBytes = inputStream.readAllBytes();
logger.info("Downloaded " + fileBytes.length + " bytes.");
// Save the byte array as a file
Path destinationPath = Paths.get(localFilePath);
try (FileOutputStream fos = new FileOutputStream(destinationPath.toFile())) {
fos.write(fileBytes);
logger.info("File saved to " + localFilePath);
} catch (IOException e) {
logger.severe("Error saving the file: " + e.getMessage());
throw e;
}
а также я пробовал использовать байты, такие как код belwo.
try {
BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(downloadPath.toFile()));
//FileOutputStream outputStream = new FileOutputStream(downloadPath.toFile());
byte[] buffer = new byte[16 * 1024]; // Buffer size (8 KB)
int bytesRead;
while ((bytesRead = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
totalBytesRead += bytesRead;
}
outputStream.flush();
logger.info("File downloaded successfully to: " + downloadPath.toString());
} catch (IOException e) {
logger.error("Error while saving the file to disk: " + e.getMessage(), e);
}
помогите пожалуйста в этом вопросе, есть ли другой способ скачать файл. Основная проблема: я не могу открывать файлы, такие как Excel и PDF.
Я также попробовал код ниже
try {
BufferedInputStream bis = new BufferedInputStream(inputStream);
BufferedOutputStream bos = new BufferedOutputStream(Files.newOutputStream(downloadPath, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING));
BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(downloadPath.toFile()));
byte[] dataBuffer = new byte[1024];
int bytesRead;
while ((bytesRead = bis.read(dataBuffer, 0, 1024)) != -1) {
bos.write(dataBuffer, 0, bytesRead);
}
outputStream.flush();
logger.info("File downloaded successfully to: " + downloadPath.toString());
} catch (IOException e) {
logger.error("Error while saving the file to disk: " + e.getMessage(), e);
}
Подробнее здесь: [url]https://stackoverflow.com/questions/79170048/facing-the-issue-with-a-corrupted-fileexcel-after-downloading-from-sharepoint[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия