Здравствуйте. Вот код для получения массива имени файлов из директории:
public class Main
{
static int c = 1;
static String loginuser;
public static void main(String[] args)
{
loginuser = "admin";
String folderName = "admin";
File folder = new File("/home/torin/NetBeansProjects/CMS/"
+ folderName + "/");
File[] files = folder.listFiles();
String[] namefiles = null;
boolean bool = folder.exists();
if(bool)
{
for(int i=0; i<files.length; i++)
{
namefiles[i] = files[i].getName();
}
}
for(int i=0; i<files.length; i++)
{
System.out.println(files[i]);
}
/*String[] namefiles = null;
for(int i=0; i<files.length; i++)
{
namefiles[i] = files[i].getName();
}*/
/*try
{
String template = "Main";
String folderName = "admin";
File folder = new File("/home/torin/NetBeansProjects/mavenproject1/" + folderName);
if (!folder.exists())
{
folder.mkdir();
}
File[] s = folder.listFiles();
if(s.length > 0)
{
for (int j = 0; j < s.length; j++)
{
c++;
}
}
String fileName = folder + "/" + "index" + c + ".jsp";
//String fileName = "index.jsp";
PrintWriter writer = new PrintWriter(fileName, "UTF-8");
if(template.equals("Main и footer"))
{
writer.println("<%@page contentType=\"text/html\" "
+ "pageEncoding=\"UTF-8\"%>");
writer.println("<!DOCTYPE html>");
writer.println("<html>");
writer.println("\t<head>");
writer.println("\t\t<meta charset=\"UTF-8\">");
writer.println("\t\t<title>Тест</title>");
writer.println("\t</head>\n");
writer.println("\t<body>");
writer.println("\t\t<main>");
writer.println("\t\t</main>");
writer.println("\t</body>");
writer.println("</html>");
}
else if(template.equals("Main и footer"))
{
writer.println("<%@page contentType=\"text/html\" "
+ "pageEncoding=\"UTF-8\"%>");
writer.println("<!DOCTYPE html>");
writer.println("<html>");
writer.println("\t<head>");
writer.println("\t\t<meta charset=\"UTF-8\">");
writer.println("\t\t<title>Тест</title>");
writer.println("\t</head>\n");
writer.println("\t<body>");
writer.println("\t\t<main>");
writer.println("\t\t</main>");
writer.println("\t\t<footer>");
writer.println("\t\t</footer>");
writer.println("\t</body>");
writer.println("</html>");
}
else if(template.equals("Header и main"))
{
writer.println("<%@page contentType=\"text/html\" "
+ "pageEncoding=\"UTF-8\"%>");
writer.println("<!DOCTYPE html>");
writer.println("<html>");
writer.println("\t<head>");
writer.println("\t\t<meta charset=\"UTF-8\">");
writer.println("\t\t<title>Тест</title>");
writer.println("\t</head>\n");
writer.println("\t<body>");
writer.println("\t\t<header>");
writer.println("\t\t</header>");
writer.println("\t\t<main>");
writer.println("\t\t</main>");
writer.println("\t</body>");
writer.println("</html>");
}
else if(template.equals("Header, main и footer"))
{
writer.println("<%@page contentType=\"text/html\" "
+ "pageEncoding=\"UTF-8\"%>");
writer.println("<!DOCTYPE html>");
writer.println("<html>");
writer.println("\t<head>");
writer.println("\t\t<meta charset=\"UTF-8\">");
writer.println("\t\t<title>Тест</title>");
writer.println("\t</head>\n");
writer.println("\t<body>");
writer.println("\t\t<header>");
writer.println("\t\t</header>");
writer.println("\t\t<main>");
writer.println("\t\t</main>");
writer.println("\t\t<footer>");
writer.println("\t\t</footer>");
writer.println("\t</body>");
writer.println("</html>");
}
writer.close();
}
catch(Exception e)
{
e.printStackTrace();
}*/
}
}
Ошибка после запуска проекта
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (default-cli) on project mavenproject1: Command execution failed. Process exited with an error: 1 (Exit value: 1) -> [Help 1]
To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.
For more information about the errors and possible solutions, please read the following articles:
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Айфон мало держит заряд, разбираемся с проблемой вместе с AppLab
Перевод документов на английский язык: Важность и ключевые аспекты
ЗдравствуйтеПочему в следующем коде переменная _message в методе Message получает null?
Выдает пустоту! Gson свеже-скачанный, на новом нетбуке
Создал проект в Jenkinse, который должен писать текст с переменными в файл пробую писать текст в файл