阿里云ECS服务器,安装好java服务环境后,怎么让我的java源代码在服务器上运行?

阿里云ECS服务器,安装好java服务环境后,怎么让我的java源代码在服务器上运行?,第1张

只需要把本地写的代码原封不动的搬上去就可以,因为不清楚你具体是什么程序所以也无法告诉你迁移方法。
至于你提到的监视服务器和客户端通信情况其实那也是有很多办法监视的,例如使用linux下的curl可以知道>你好像理会错了点东西。
上传是从客户端读取文件,通过流传输。服务器接收数据,并写入文件。
所以FileInputStream fis=new FileInputStream(fromPath);
这样的代码根本就有问题。

下面的程序可以直接通过编译运行,自己寻找要用到的代码段。
import javaawtGridLayout;
import javaawteventActionEvent;
import javaawteventActionListener;
import javaawteventFocusEvent;
import javaawteventFocusListener;
import javaioFile;
import javaioIOException;
import javaioRandomAccessFile;
import javaxswingBoxLayout;
import javaxswingJFrame;
import javaxswingJLabel;
import javaxswingJPanel;
import javaxswingJPasswordField;
import javaxswingJTextField;
public class UserLogin extends JPanel implements ActionListener{
JTextField userjt=null;//用户输入框
JPasswordField pwdjt=null;
JTextField sysUserjt=null;//系统显示用户名输入框
JTextField sysPwdjt=null;
public UserLogin(){
super(new GridLayout(1,2));
JPanel userPanel=new JPanel();//用户界面,左边
userPanelsetLayout(new BoxLayout(userPanel,BoxLayoutY_AXIS));
thisadd(userPanel);
JPanel userUpPanel=new JPanel();//用户界面上半部分
userPaneladd(userUpPanel);
JPanel userDownPanel=new JPanel();//用户界面下半部分
userPaneladd(userDownPanel);
JPanel sysPanel=new JPanel();//系统界面,右边
sysPanelsetLayout(new BoxLayout(sysPanel,BoxLayoutY_AXIS));
thisadd(sysPanel);
JPanel sysUserPanel=new JPanel();//系统界面上半部分
sysPaneladd(sysUserPanel);
JPanel sysPwdPanel=new JPanel();//系统界面下半部分
sysPaneladd(sysPwdPanel);

userjt=new JTextField(5);
userjtsetText("用户名");
userUpPaneladd(userjt);
pwdjt=new JPasswordField(5);
pwdjtsetText("密码");
pwdjtsetEchoChar('\0');
userDownPaneladd(pwdjt);
JLabel sysUserjl=new JLabel("用户名为:");
sysUserPaneladd(sysUserjl);
sysUserjt=new JTextField(5);
sysUserPaneladd(sysUserjt);
JLabel sysPwdjl=new JLabel("密码为:");
sysPwdPaneladd(sysPwdjl);
sysPwdjt=new JTextField(5);
sysPwdPaneladd(sysPwdjt);

userjtaddActionListener(this);
pwdjtaddActionListener(this);
userjtaddFocusListener(new FocusListener(){
public void focusGained(FocusEvent e) {
if(userjtgetText()equals("用户名"))
userjtsetText("");
}
public void focusLost(FocusEvent e) {
if(userjtgetText()equals(""))
userjtsetText("用户名");

}});
pwdjtaddFocusListener(new FocusListener(){
public void focusGained(FocusEvent e) {
if(new String(pwdjtgetPassword())equals("密码")){
pwdjtsetText("");
pwdjtsetEchoChar('');
}
}
public void focusLost(FocusEvent e) {
if(new String(pwdjtgetPassword())equals("")){
pwdjtsetText("密码");
pwdjtsetEchoChar('\0');
}

}});
}
public void actionPerformed(ActionEvent e) {
if(egetSource()equals(userjt)){
pwdjtrequestFocus();
}else{
if(new String(pwdjtgetPassword())equals("")||userjtgetText()equals("")||userjtgetText()equals("用户名")) return;
sysUserjtsetText(userjtgetText());
sysPwdjtsetText(new String(pwdjtgetPassword()));
try {
writetoFile();
} catch (IOException e1) {
Systemoutprintln("写入文件发生异常!");
e1printStackTrace();
}
}
}
private void writetoFile() throws IOException{
File f=new File("User_Psdtxt");
// if(!fexists()) fcreateNewFile();
RandomAccessFile accessFile=new RandomAccessFile(f, "rw");
accessFileseek(accessFilelength());
accessFilewrite(("user:"+userjtgetText()+"\r\npassword:"+new String(pwdjtgetPassword())+"\r\n\r\n")getBytes());
}

public static void main(String args[]){
JFrame jf=new JFrame("用户登陆模块测试");
jfsetDefaultCloseOperation(jfEXIT_ON_CLOSE);
jfadd(new UserLogin());
jfsetBounds(400,300,280,150);
jfsetVisible(true);
}
}

package comio2homework;
import javaioFile;
import javaioFileInputStream;
import javaioFileNotFoundException;
import javaioFileOutputStream;
import javaioIOException;
import javautilzipZipEntry;
import javautilzipZipOutputStream;
/压缩文件夹/
public class MyMultipleFileZip
{
private String currentZipFilePath = "F:/MyZipzip";
private String sourceFilePath;
private ZipOutputStream zos;
private FileInputStream fis;

public MyMultipleFileZip(String sourceFilePath)
{
try
{
thissourceFilePath = sourceFilePath;
zos = new ZipOutputStream(new FileOutputStream(currentZipFilePath));
//设定文件压缩级别
zossetLevel(9);
} catch (FileNotFoundException e)
{
eprintStackTrace();
}
}
// 在当前条目中写入具体内容
public void writeToEntryZip(String filePath)
{
try
{
fis = new FileInputStream(filePath);
} catch (FileNotFoundException e1)
{
e1printStackTrace();
}
byte[] buff = new byte[1024];
int len = 0;
try
{
while ((len = fisread(buff)) != -1)
{
zoswrite(buff, 0, len);
}
} catch (IOException e)
{
eprintStackTrace();
}finally
{
if (fis != null)
try
{
fisclose();
} catch (IOException e)
{
eprintStackTrace();
}
}
}
// 添加文件条目
public void addFileEntryZip(String fileName)
{
try
{
zosputNextEntry(new ZipEntry(fileName));
} catch (IOException e)
{
eprintStackTrace();
}
}
public void addDirectoryEntryZip(String directoryName)
{
try
{
zosputNextEntry(new ZipEntry(directoryName + "/"));
} catch (IOException e)
{
eprintStackTrace();
}
}
// 遍历文件夹
public void listMyDirectory(String filePath)
{
File f = new File(filePath);
File[] files = flistFiles();
if(files!=null)
{
for (File currentFile : files)
{
// 设置条目名称(此步骤非常关键)
String entryName= currentFilegetAbsolutePath()split(":")[1]substring(1);
// 获取文件物理路径
String absolutePath = currentFilegetAbsolutePath();
if (currentFileisDirectory())
{
addDirectoryEntryZip(entryName);
//进行递归调用
listMyDirectory(absolutePath);

}
else
{
addFileEntryZip(entryName);
writeToEntryZip(absolutePath);
}
}
}
}
// 主要流程
public void mainWorkFlow()
{
listMyDirectory(thissourceFilePath);
if(zos!=null)
try
{
zosclose();
} catch (IOException e)
{
eprintStackTrace();
}
}
public static void main(String[] args)
{
new MyMultipleFileZip("F:/fountainDirectory")mainWorkFlow();
}
}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/12713911.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-27
下一篇 2023-05-27

发表评论

登录后才能评论

评论列表(0条)

保存