第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何在新文件中轉(zhuǎn)義問(wèn)題斜杠?

如何在新文件中轉(zhuǎn)義問(wèn)題斜杠?

慕標(biāo)琳琳 2023-04-26 15:57:31
我有這個(gè) :fos = new FileOutputStream(new File(cdn.replace('/', File.separatorChar), request.getEntity().getNewfilepath()));我也試過(guò)這個(gè):fos = new FileOutputStream(new File(cdn, request.getEntity().getNewfilepath()));但我收到一個(gè)錯(cuò)誤:java.io.FileNotFoundException: http:\cdn\test.jpg(文件名、目錄名或卷標(biāo)語(yǔ)法不正確)任何建議我該如何解決?cdn是網(wǎng)址:http://cdn我想要實(shí)現(xiàn)的是將文件保存在http://cdn/test.jpg
查看完整描述

1 回答

?
繁花不似錦

TA貢獻(xiàn)1851條經(jīng)驗(yàn) 獲得超4個(gè)贊

正斜杠總是有效,在 Windows 上也是如此。

并且反斜線絕對(duì)不適用于 URL。

在您對(duì) Abra 做出回應(yīng)后,我更了解您想做什么。您需要將 URL 作為輸入流打開(kāi),并創(chuàng)建一個(gè)指向本地文件的新輸出流。

文件理解 http 布局,因此您可以使用它來(lái)獲取包含文件名的 url 的最后一部分(參見(jiàn)變量 f):

File 也有一個(gè)帶有 2 個(gè)參數(shù)的構(gòu)造

import java.io.File;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.InputStream;

import java.io.OutputStream;

import java.net.URL;


public class InternetReader {


? ? private static void copyInputStreamToOutputstream(InputStream in, OutputStream out) throws IOException {

? ? ? ? byte[] buf = new byte[1024];

? ? ? ? int len;

? ? ? ? while ((len = in.read(buf)) > 0) {

? ? ? ? ? ? out.write(buf, 0, len);

? ? ? ? }

? ? }


? ? public static void main(String[] args) throws IOException {

? ? ? ? File f = new File("http://google.be/test.jpg");

? ? ? ? System.out.println(f.getName());

? ? ? ? File localPath = new File("/cdn/opt");

? ? ? ? File localDestination = new File(localPath, f.getName());

? ? ? ? URL remoteURL = new URL("http://google.be/test.jpg");

? ? ? ? try (InputStream is = remoteURL.openStream(); OutputStream os = new FileOutputStream(localDestination)) {

? ? ? ? ? ? copyInputStreamToOutputstream(is, os);

? ? ? ? }

? ? }


}


查看完整回答
反對(duì) 回復(fù) 2023-04-26
  • 1 回答
  • 0 關(guān)注
  • 136 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)