读取下载的文本文件-FileNotFoundException

时间:2018-07-30 16:36:03

标签: java android json filenotfoundexception

plz帮助,我正在尝试从此Google翻译API URL获取数据 而且只有在值是1个单词的情况下它才起作用。如果它的2个值给我一个错误。

我的意思是,这将有效:

String sourceLang = "auto";
String targetLang = "en";
String sourceText = "olas";
String urlstring = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=" + sourceLang + "&tl=" + targetLang + "&dt=t&q=" + sourceText;

但是如果我用2个词来表示它:

String sourceText = "olas olas";

它将给我filenotfoundexception错误

这是代码:

        URL url = new URL(urlstring);
        HttpURLConnection httpURLconnection = (HttpURLConnection) url.openConnection();
        httpURLconnection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.62 Safari/537.36");
        InputStream inputStream = httpURLconnection.getInputStream();
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
        String line = "";
        while(line != null){
            line = bufferedReader.readLine();
            data = data + line;
        }

1 个答案:

答案 0 :(得分:1)

用“%20”代替空格

        <plugin>
            <groupId>org.jsonschema2pojo</groupId>
            <artifactId>jsonschema2pojo-maven-plugin</artifactId>
            <version>0.4.37</version>
            <executions>
                <execution>
                    <id>exec-id</id>
                    <configuration>
                        <sourceDirectory>${basedir}/src/main/resources/schema/json</sourceDirectory>
                        <targetPackage>org.jozefowicz</targetPackage>
                        <inclusionLevel>ALWAYS</inclusionLevel>
                    </configuration>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
相关问题