I want combine this code
this is to get user input
import java.util.Scanner;
public class scanner
{
private static Scanner scanner = new Scanner( System.in );
public static void main ( String [] args )
{
System.out.print( "Enter your first image file path : " );
String input1 = scanner.nextLine();
}
}
with this
and this is to zip current directory
class ZipFolder
{
public static void main(String[] args) throws Exception
{
ZipFolder zf = new ZipFolder();
String folderToZip = System.getProperty("user.dir");
String zipName = System.getProperty("user.dir") + ".zip";
zf.zipFolder(Paths.get(folderToZip), Paths.get(zipName));
}
private void zipFolder(Path sourceFolderPath, Path zipPath) throws Exception
{
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipPath.toFile()));
Files.walkFileTree(sourceFolderPath, new SimpleFileVisitor < Path > ()
{
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException
{
zos.putNextEntry(new ZipEntry(sourceFolderPath.relativize(file).toString()));
Files.copy(file, zos);
zos.closeEntry();
return FileVisitResult.CONTINUE;
}
});
zos.close();
}
}
to zip path of file that get from user input //I want to get path of file from user then find that file and zip that
Comments
Post a Comment