내가이 질문 " AAAAAA"
에서 문자열을 복사하여 교체 할 때처럼 보일 UPDATE. 프로그램이 올바르게 작동합니다.
그래서 이전의 오류 문자열을 " AAAAAA"
으로 변경하여 테스트를 수행합니다. 그런 다음 모든 공백을 제거하고 입력하여 수동으로 입력하면 작동합니다!?!? 여기
public static void main(String[] args) {
URL url;
InputStream is = null;
try {
url = new URL(
"http://writer.dek-d.com/nattione/story/viewlongc.php?id=466201&chapter=966");
is = url.openStream(); // throws an IOException
String result = convertStreamToString(is);
createFictionFiles(result);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
is.close();
} catch (IOException e) {
// nothing to see here
}
}
}
public static void createFictionFiles(String html) {
Document doc = Jsoup.parse(html);
Element title = doc.select("title").first();
Element table = doc.select("#story_body").first();
String showTitle = "";
String showStory = "";
BufferedWriter bw;
try {
showTitle = new String(title.text());
showStory = new String(table.text());
//showStory = " AAAAAA"; these spaces I copy it from log in eclipse. It is the spaces that come from web
boolean find = showStory.contains("\\t");
boolean find1 = showStory.contains("\\n");
boolean find2 = showStory.contains("\\x0b");
boolean find3 = showStory.contains("\\r");
boolean find4 = showStory.contains("\\f");
boolean find5 = showStory.contains(" ");
boolean find6 = showStory.contains(" ");
boolean find7 = showStory.matches("\\s");
System.out.println("\\t = " + find);
System.out.println("\\n = " + find1);
System.out.println("\\x0b = " + find2);
System.out.println("\\r = " + find3);
System.out.println("\\f = " + find4);
System.out.println(" = " + find5);
System.out.println(" = " + find6);
System.out.println("\\s = " + find7);
File file = new File("D:/" + "test"
+ ".txt");
if (!file.exists()) {
file.createNewFile();
}
FileWriter fw = new FileWriter(file.getAbsoluteFile());
bw = new BufferedWriter(fw);
bw.write(showStory);
bw.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static String convertStreamToString(InputStream is) {
Scanner s = new Scanner(is, "TIS-620").useDelimiter("\\A");
return s.hasNext() ? s.next() : "";
}
OLD 내 전체 코드
내가 가진이 String
showStory = " AAAAAA";
이러한 문자열은 웹에서 검색하고 library
를 사용하여 문자열 형식으로 구문 분석입니다공간을 3 인치 이상으로 나누고 싶습니다. "\n"
나는이 검사를받습니다.
boolean find = showStory.contains("\\t");
boolean find1 = showStory.contains("\\n");
boolean find2 = showStory.contains("\\x0b");
boolean find3 = showStory.contains("\\r");
boolean find4 = showStory.contains("\\f");
boolean find5 = showStory.contains(" ");
boolean find6 = showStory.contains(" ");
boolean find7 = showStory.contains("\\s");
결과는 8 공백이도 내 문자열에 불구하고 하나 개 이상의 공간이 나에게 거짓주는 이유를 모르겠어요
\t = false
\n = false
\x0b = false
\r = false
\f = false
= true
= false
\s = false
있습니다. 또한 메서드를 contains
에서 matches
으로 변경하지만 모든 결과가 false입니다.
아무도 도와 줄 수 있습니까?
감사합니다.
에 코드를 [내가 그것을 실행하면 true를 반환 에 ideone] (http://ideone.com/iEs7Z7). 내가 뭘 놓치고 있니? – dasblinkenlight
실제로 달성하려는 목표는 무엇입니까? – Adude11
정확하게 동일한 입력을 가진 작은 프로그램을 작성하고 길이가 8 인 모든 공백에 대해 'true'를 받았습니다. –