2013-08-22 119 views
4

我的代碼是 的test.html:如何多的html代碼轉換成一行的html代碼

<!DOCTYPE html> 
<html> 
<body> 

<h1>My First Heading</h1> 

<p>My first paragraph.</p> 

</body> 
</html> 

轉換爲

<!DOCTYPE html><html><body><h1>My First Heading</h1><p>My first paragraph.</p></body></html> 

我使用手動轉換,請告訴我有什麼在線轉換器,用於將多行html代碼轉換爲單行html

+0

使用Java程序? – sanbhat

+0

你爲什麼要這樣做? –

+0

你可以搜索'html minifier'和問題http://stackoverflow.com/questions/728260/html-minification –

回答

1

嘗試使用StringUtils.chomp

BufferedReader bufferedReader = new BufferedReader(new FileReader(FILE_NAME)); 
     String s = null; 
     StringBuilder stringBuilder = new StringBuilder(); 
     while((s = bufferedReader.readLine()) != null) 
     { 
      stringBuilder.append(StringUtils.chomp(s)); 
     } 

     System.out.println("stringBuilder : "+stringBuilder);