有没有办法迭代java Hashmap并打印出作为Hashmap一部分的每个键的所有值?
我正在研究一个套接字监听器,它必须在2个端口上侦听2种类型的数据(端口80和端口81).这些数据与对数据执行的操作类型非常相似,只是因为它们到达不同的端口而不同.我继续使用Java的ServerSocket类编写实现,但后来才意识到ServerSocket类的accept()方法是块,我的实现无法承受.所以现在我正在考虑使用Java NIO实现相同的功能,但在完成了一些教程之后,我认为我比我开始时更困惑.如果这里的某个人可以引导我完成整个过程,即使它是伪代码或技术"下一步该做什么",那将是很棒的.这就是我打算实现的目标.
通过调用2个类似的线程来监听,就像永远在2个端口上一样.(非阻塞)来自某个网络位置的远程设备连接,发送数据然后断开连接.
我想如果只知道如何使用NIO设置服务器来监听端口,那么就可以实现localhost上的端口80,其余的都很容易实现.
干杯
我开发了一个不支持纵向模式的XAML/C#Windows 8应用程序.我在Visual Studio中打开了Package.appxmanifest,并在"支持的旋转"下禁用了纵向和纵向翻转模式.这创建了以下旋转首选项:
<InitialRotationPreference>
<Rotation Preference="landscape" />
<Rotation Preference="landscapeFlipped" />
</InitialRotationPreference>
Run Code Online (Sandbox Code Playgroud)
但是,当我在模拟器中启动我的应用程序并旋转模拟器时,应用程序仍然会旋转到纵向模式.我怎么能防止这种情况发生?
谢谢,
阿德里安
我需要生成一个excel表报告,看起来像以下模板 -

我知道这可以使用像JExcelApi和的库来完成Apache POI.但是,我想知道是否有办法通过编写类似于编写Apache Velocity模板来发送电子邮件的模板来完成此操作.
如果有一个标准的,良好实践的方法来生成这样的报告是什么?
我有一个写有一个邮件构建部分的库.该邮件构建部分使用Velocity.mailbuilder类如下 -
public class mailBuilder {
public void initialize() throws Exception
{
Properties props = new Properties();
log.info("About to set the ClassPath for Velocity specific tasks");
props.setProperty(VelocityEngine.RESOURCE_LOADER, "classpath");
props.setProperty("classpath." + VelocityEngine.RESOURCE_LOADER + ".class", ClasspathResourceLoader.class.getName());
try
{
log.info("Just before");
Velocity.init(props);
log.info("Just after");
}
catch ( Exception e )
{
log.error( "Caught Execption on velocityEngine init", e );
throw new Exception( "Caught Execption on velocityEngine init", e );
}
log.info("Completed initializing Velocity Engine");
}
public String returnMailstring() throws Exception {
initialize();
.... …Run Code Online (Sandbox Code Playgroud) 我之前发布了一个关于Java线程的查询.(链接文字)
根据我收到的答案,我决定实施它们.所以我在具有2个CPU内核的机器上完成了这一点编码.代码如下
import java.net.*;
import java.io.*;
public class thready implements Runnable{
private Socket num;
public thready(Socket a) {
this.num=a;
}
public void run() {
try {
BufferedInputStream is = new BufferedInputStream(num.getInputStream());
System.out.println("Connected to port"+num);
} catch (IOException ex) {
//Logger.getLogger(thready.class.getName()).log(Level.SEVERE, null, ex);
}
}
public static void main(String [] args)
{
int port = 80;
int port1= 81;
//int count = 0;
try{
ServerSocket socket1 = new ServerSocket(port);
ServerSocket socket2 = new ServerSocket(port1);
while (true) {
Socket connection …Run Code Online (Sandbox Code Playgroud) 我试图将JPanel添加到另一个JPanel,但我遇到的问题是第二个Jpanel不会出现在第一个.
事情的基本结构如下 -
我有JPanel panel1一个BoxLayout并且凭借HorizontalBoxes而且VerticalBoxes我不断添加JComponents它.JComponents除第二个外,所有都出现在panel1上JPanel.第二个JPanel不会出现的代码如下 -
public class LabelMacroEditor extends JPanel implements PropertyChangeListener {
private static final long serialVersionUID = 1L;
private LabelMacroModel model;
public LabelMacroEditor(LabelMacroModel bean) {
this.model = bean;
model.addPropertyChangeListener(this);
setupComponents();
validate();
setVisible(true);
}
public void setupComponents()
{
Box allButtons = Box.createVerticalBox();
for(MacroModel macroModel : model.getMacroModelList())
{
LabelMacroEditorEditableEntity macroEditorEntity = new LabelMacroEditorEditableEntity(macroModel);
Box entityBox = Box.createHorizontalBox();
entityBox.add(macroEditorEntity.getUpButton());
entityBox.add(Box.createHorizontalStrut(15));
entityBox.add(macroEditorEntity.getMacroDetailsButton());
entityBox.add(Box.createHorizontalStrut(15));
entityBox.add(macroEditorEntity.getDownButton());
allButtons.add(entityBox); …Run Code Online (Sandbox Code Playgroud) 我正在研究涉及线程的java应用程序.所以我只是编写了一段代码来熟悉多个并发线程的执行
public class thready implements Runnable{
private int num;
public thready(int a) {
this.num=a;
}
public void run() {
System.out.println("This is thread num"+num);
for (int i=num;i<100;i++)
{
System.out.println(i);
}
}
public static void main(String [] args)
{
Runnable runnable =new thready(1);
Runnable run= new thready(2);
Thread t1=new Thread(runnable);
Thread t2=new Thread(run);
t1.start();
t2.start();
}}
Run Code Online (Sandbox Code Playgroud)
现在从这段代码的输出中,我认为在任何时间点只有1个线程正在执行,并且执行似乎在线程之间交替.现在我想知道我对情况的理解是否正确.如果它是我想知道是否有任何方式我可以让两个线程同时执行,因为我希望将这种情况合并到我希望编写同时侦听2的tcp/ip套接字侦听器的情况港口,同时.而这种情况不能有任何停机时间.任何建议/意见都会有很大帮助.
干杯
我正在研究一个tcp/ip套接字侦听器,它在端口80上侦听从远程主机到达的数据.现在这些传入的数据是不可读的格式,因此我保存了这些传入数据,因为它们最初是在字符串中,然后将此字符串转换为字符数组,然后对于数组中的每个索引,我已将内容转换为十六进制.现在问题是数据转换为十六进制正常,但在某些地方转换不正确,结果十六进制部分是'fffd'.在得到的十六进制应该是'bc'(0xBC)的地方,它是'fffd'(0xFF 0xFD).我不得不相信我的java程序无法正确读取传入数据的某些部分.
BufferedInputStream is = new BufferedInputStream(connection.getInputStream());
InputStreamReader isr = new InputStreamReader(is);
while(isr.read()!=-1)
{
...
}
Run Code Online (Sandbox Code Playgroud)
其中'connection'是套接字对象.
我通过套接字输入的数据是#SR,IN-0002005,10:49:37,16/01/2010,$ <49X™š@(bN>™BB©:4äý01300>ÀäCåKöA÷ d>.
我的程序所做的十六进制转换在其他十六进制值应该在的许多地方都有'fffd'.但是转换对于输入字符串的大约60%是正确的
关于为什么我的结果十六进制转换不是它应该是什么的任何指针将是非常有帮助的.
我目前正在使用java应用程序通过调用bash的实例在unix框上运行命令,如下所示 -
proc = Runtime.getRuntime().exec("/bin/bash", null, wd);
Run Code Online (Sandbox Code Playgroud)
我在Printwriter的盒子上执行命令,如下所示 -
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(proc.getOutputStream())), true);
Run Code Online (Sandbox Code Playgroud)
现在,作为一个要求我需要ssh到另一个主机上,调用该主机的bash实例并运行一些命令.如果可以在不输入密码的情况下完成,那就太棒了.如果没有,我如何让应用程序在合适的时间输入"密码"?读取shh命令的输出并基于此,写出密码似乎并不吸引人.
任何有关上述内容的指示都会有很大帮助.
关心p1nG
java ×9
apache-poi ×1
c# ×1
concurrency ×1
excel ×1
hashmap ×1
iteration ×1
jexcelapi ×1
jpanel ×1
nonblocking ×1
orientation ×1
passwords ×1
reporting ×1
sockets ×1
ssh ×1
string ×1
swing ×1
unix ×1
velocity ×1
windows-8 ×1