VS项目在A电脑上打包,并且吧A电脑作为服务器。然后把安装包,复制到电脑B上面,但是电脑B安装后,不能用

VS项目在A电脑上打包,并且吧A电脑作为服务器。然后把安装包,复制到电脑B上面,但是电脑B安装后,不能用,第1张

1,你检查下服务器是否设置允许远程连接,在SQL工具里面有个单选框

2,你检查下你打包的包里面是否包含链接数据库的配置文件

3,就是检查下软件环境framework什么的

java">下面是我自己写的一个读取并显示txt文件的demo,希望对您有帮助。publicclassClient{publicstaticvoidmain(String[]args){ClientFramef=newClientFrame()}}importjava.awt.BorderLayoutimportjava.awt.Containerimportjava.awt.Dimensionimportjava.awt.GridLayoutimportjava.awt.Toolkitimportjava.awt.event.ActionEventimportjava.awt.event.ActionListenerimportjava.io.DataInputStreamimportjava.io.DataOutputStreamimportjava.io.IOExceptionimportjava.net.Socketimportjava.net.UnknownHostExceptionimportjava.util.Vectorimportjavax.swing.BorderFactoryimportjavax.swing.JButtonimportjavax.swing.JFrameimportjavax.swing.JListimportjavax.swing.JScrollPaneimportjavax.swing.JTextAreaimportjavax.swing.event.ListSelectionEventimportjavax.swing.event.ListSelectionListenerpublicclassClientFrameextendsJFrameimplementsActionListener,ListSelectionListener{privateJListlist=nullprivateJButtonsbtn=nullprivateJButtoncbtn=nullprivateVectorv=nullprivateJTextAreatxt=nullprivateContainercontrol=nullprivateContainerbtn=nullprivateSocketclient=nullprivateDataInputStreamreader=nullprivateDataOutputStreamwriter=nullpublicClientFrame(){this.list=newJList()this.list.setBorder(BorderFactory.createTitledBorder("文件列表"))this.list.addListSelectionListener(this)this.sbtn=newJButton("显示")this.sbtn.addActionListener(this)this.cbtn=newJButton("清除")this.cbtn.addActionListener(this)this.control=newContainer()this.control.setPreferredSize(newDimension(150,400))this.control.setLayout(newBorderLayout())this.control.add(newJScrollPane(this.list),BorderLayout.CENTER)this.btn=newContainer()this.btn.setLayout(newGridLayout(1,2))btn.add(sbtn)btn.add(cbtn)this.control.add(this.btn,BorderLayout.SOUTH)this.txt=newJTextArea()this.txt.setEditable(false)this.txt.setSize(350,400)this.setTitle("客户端")this.setSize(500,400)this.setVisible(true)DimensiondisplaySize=Toolkit.getDefaultToolkit().getScreenSize()this.setLocation((displaySize.width-this.getWidth())/2,(displaySize.height-this.getHeight())/2)this.setLayout(newBorderLayout())this.add(this.control,BorderLayout.WEST)this.add(newJScrollPane(this.txt),BorderLayout.CENTER)this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)try{//this.client=newSocket("192.168.32.34",6666)this.client=newSocket("192.168.1.100",6666)this.reader=newDataInputStream(client.getInputStream())this.writer=newDataOutputStream(client.getOutputStream())}catch(UnknownHostExceptione){e.printStackTrace()}catch(IOExceptione){e.printStackTrace()}}publicvoidactionPerformed(ActionEventevent){if(event.getSource()==sbtn){if(v==null){v=newVector()}else{v.clear()}try{writer.writeUTF("getfilelist")writer.flush()Stringt=reader.readUTF()while(t!=null&&!t.equals("")){v.add(t)t=reader.readUTF()}}catch(UnknownHostExceptione){e.printStackTrace()}catch(IOExceptione){e.printStackTrace()}this.list.setListData(v)}if(event.getSource()==cbtn){this.txt.setText("")}}publicvoidvalueChanged(ListSelectionEvente){inti=this.list.getSelectedIndex()if(!this.list.getValueIsAdjusting()&&i!=-1){try{writer.writeUTF("getfilecontent_"+i)writer.flush()Stringtmp=reader.readUTF()this.txt.setText(tmp)}catch(IOExceptione1){e1.printStackTrace()}}}}importjava.io.DataInputStreamimportjava.io.DataOutputStreamimportjava.io.Fileimportjava.io.FileInputStreamimportjava.io.IOExceptionimportjava.io.InputStreamReaderimportjava.io.Readerimportjava.net.ServerSocketimportjava.net.Socketimportjava.util.ArrayListimportjava.util.IteratorpublicclassServer{staticArrayListfileArray=newArrayList()publicstaticvoidmain(Stringargs[]){ServerSocketserver=nullSocketclient=nullStringcmd=""try{server=newServerSocket(6666)client=server.accept()DataInputStreamreader=newDataInputStream(client.getInputStream())DataOutputStreamwriter=newDataOutputStream(client.getOutputStream())while(true){cmd=reader.readUTF()System.out.println(cmd)if(cmd.equals("getfilelist")){fileArray.clear()//fileArray=getFile(newFile("D:/tmp"))fileArray=getFile(newFile("D:/学习/教程/学习笔记"))Stringfn=""for(intk=0kgetFile(Filef){File[]ff=f.listFiles()for(Filechild:ff){if(child.isDirectory()){getFile(child)}else{fileArray.add(child)}}returnfileArray}}


欢迎分享,转载请注明来源:夏雨云

原文地址:https://www.xiayuyun.com/zonghe/788210.html

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

发表评论

登录后才能评论

评论列表(0条)

    保存