創(chuàng)建ftp用戶名和密碼,其實就在ftp服務器的用戶文件里面添加條記錄。
衛(wèi)輝網(wǎng)站建設公司創(chuàng)新互聯(lián),衛(wèi)輝網(wǎng)站設計制作,有大型網(wǎng)站制作公司豐富經(jīng)驗。已為衛(wèi)輝成百上千提供企業(yè)網(wǎng)站建設服務。企業(yè)網(wǎng)站搭建\成都外貿網(wǎng)站制作要多少錢,請找那個售后服務好的衛(wèi)輝做網(wǎng)站的公司定做!
方法有兩種,我說下思路。
一、你可以用java程序找到相應的配置文件,打開、把用戶名密碼寫入進去。ok了。
二、你用用java程序調用創(chuàng)建ftp用戶的命令,來創(chuàng)建ftp用戶。
源程序如下:
import java.awt.Button;
import java.awt.GridLayout;
import java.awt.Panel;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
public class LoginValidation extends JFrame implements ActionListener{
private Panel pan = new Panel();
private Button login = new Button("login");
private TextField username = new TextField(10);
private JLabel opl1 = new JLabel("please login with username");
public LoginValidation() {
super("Login");
initialize();
}
public void initialize() {
this.setLayout(null);
this.setSize(360, 200);
this.setResizable(false);
this.add(pan);
pan.setBounds(10, 10, 330, 250);
pan.setLayout(new GridLayout(5, 1));
pan.add(opl1);
pan.add(username);
login.addActionListener(this);
pan.add(login);
this.setVisible(true);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==login){
String str = username.getText().trim();
if(str.equals("")|| str.equals(null))
{
JOptionPane.showMessageDialog(null,"username can be empty!!","username",JOptionPane.ERROR_MESSAGE);
return;
}
Pattern pt = Pattern.compile("^\\d{10}$");
Matcher m = pt.matcher(str);
if(m.matches()){
char c = str.charAt(0);
if(String.valueOf(c).equals("0")){
JOptionPane.showMessageDialog(null,"the first number can't be 0!!!","username",JOptionPane.ERROR_MESSAGE);
username.setText("");
repaint();
return;
}
else{
JOptionPane.showMessageDialog(null,"login success!!!","username",JOptionPane.INFORMATION_MESSAGE);
}
}
else{
JOptionPane.showMessageDialog(null,"username must be 10 numbers!!","username",JOptionPane.ERROR_MESSAGE);
username.setText("");
repaint();
}
}
}
public static void main(String[] args) {
new LoginValidation();
}
}
import java.util.Scanner;
public class Logon {
private static final char username = '青';
private static final int password = 123;
private static final Scanner san = new Scanner(System.in);
public static void main(String[] args) {
char iname;
int ipass;
System.out.print("請輸入用戶名: ");
iname = san.next().charAt(0);
System.out.print("請輸入密碼: ");
ipass = san.nextInt();
if(Logon.username == iname Logon.password == ipass) {
System.out.println("歡迎你, " + Logon.username);
} else {
System.out.println("對不起, 你不是" + Logon.username);
}
}
}
分析需求
輸入 :John?Smith
輸出:JSmith
John是常用人名.?Smith是姓氏. 中間使用空白分開
主要考查的字符串的操作
參考代碼
import?java.util.Scanner;
public?class?NameDemo?{
public?static?void?main(String[]?args)?{
System.out.println("請輸入名字:");
Scanner?sc?=?new?Scanner(System.in);
String?name?=?sc.nextLine().trim();
String[]?ss?=?name.split("\\s+");//?\s表示用空白切割字符串,?+表示1個或者多個空白
String?ming?=?ss[0];//名
String?xing?=?ss[1];//姓
System.out.println(ming.charAt(0)+xing);//?ming.charAt(0)表示取得該字符串的第一個字符
}
}
運行測試
請輸入名字:
John?Smith
JSmith