在Java应用程序中,我正在使用一些调用System.out.println().现在我想找到一种以编程方式删除这些东西的方法.
我找不到谷歌的任何解决方案,所以有任何提示吗?
我正在使用以下代码在Java应用程序中使用Git.我有一个有效的密钥(一直使用它),这个特定的代码以前使用相同的密钥和git存储库,但现在我得到以下异常:无效的私钥:[B @ 59c40796.
jSch.addIdentity("<key_path>/private_key.pem");
Run Code Online (Sandbox Code Playgroud)
在线搜索后,我将createDefaultJSch更改为使用pemWriter:
String remoteURL = "ssh://git@<git_repository>";
TransportConfigCallback transportConfigCallback = new SshTransportConfigCallback();
File gitFolder = new File(workingDirectory);
if (gitFolder.exists()) FileUtils.delete(gitFolder, FileUtils.RECURSIVE);
Git git = Git.cloneRepository()
.setURI(remoteURL)
.setTransportConfigCallback(transportConfigCallback)
.setDirectory(new File(workingDirectory))
.call();
}
private static class SshTransportConfigCallback implements TransportConfigCallback {
private final SshSessionFactory sshSessionFactory = new JschConfigSessionFactory() {
@Override
protected void configure(OpenSshConfig.Host hc, Session session) {
session.setConfig("StrictHostKeyChecking", "no");
}
@Override
protected JSch createDefaultJSch(FS fs) throws JSchException {
JSch jSch = super.createDefaultJSch(fs);
jSch.addIdentity("<key_path>/private_key.pem");
return jSch;
}
};
Run Code Online (Sandbox Code Playgroud)
但仍然得到无效的privateKey异常.
我用Java创建了一个二维数组,我正在寻找一种在控制台上打印它的方法,以便我可以确认我正在制作的东西是正确的.我在网上发现了一些为我执行此任务的代码,但我对代码的特定含义有疑问.
int n = 10;
int[][] Grid = new int[n][n];
//some code dealing with populating Grid
void PrintGrid() {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
System.out.print(Grid[i][j] + " ");
}
System.out.print("\n");
}
}
Run Code Online (Sandbox Code Playgroud)
"\n"有什么作用?我尝试在谷歌上搜索,但由于这是一小段代码,我找不到多少.
我刚学会了当按回车键响应a时System.in.read(),将以下字符放入控制台缓冲区,\r\n.因此,当我将以下内容输入1终端并按Enter键时,计算机将该语句读作1\r\n.所以不System.out.println("hello")应该两次被罚款?因为choice会存储价值1.然后,"hello"将被打印.然后,ignore将保持该值\r.然后,控制将while(ignore != '\n')循环.然后,ignore将保持该值\n.然后,"hello"将被打印.现在ignore = \n,代码将突破循环?
class HelpClassDemo {
public static void main(String args[])
throws java.io.IOException {
char choice, ignore;
for(;;) {
do {
System.out.println("Help on:");
System.out.println(" 1. if");
System.out.println(" 2. switch");
System.out.println(" 3. for");
System.out.println(" 4. while");
System.out.println(" 5. do-while");
System.out.println(" 6. break");
System.out.println(" 7. continue\n");
System.out.print("Choose one (q to …Run Code Online (Sandbox Code Playgroud) newLine()和回车("\ r")之间有什么区别?哪一个最好用?
File f = new File(strFileGenLoc);
BufferedWriter bw = new BufferedWriter(new FileWriter(f, false));
rs = stmt.executeQuery("select * from jpdata");
while ( rs.next() )
{
bw.write(rs.getString(1)==null? "":rs.getString(1));
bw.newLine();
}
Run Code Online (Sandbox Code Playgroud) Spring in Action 的第 02 章,第 2 页。40 使用 Spring Tool Suite,我做了以下事情:
媒体播放器界面
package com.spring.soundsystem;
public interface MediaPlayer {
void play();
}
Run Code Online (Sandbox Code Playgroud)
光盘接口
package com.spring.soundsystem;
public interface CompactDisc {
void play();
}
Run Code Online (Sandbox Code Playgroud)
CDPlayer 类实现 MediaPlayer
package com.spring.soundsystem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class CDPlayer implements MediaPlayer {
private CompactDisc cd;
@Autowired
public CDPlayer(CompactDisc cd) {
this.cd = cd;
}
public void play() {
cd.play();
}
}
Run Code Online (Sandbox Code Playgroud)
SgtPeppers 类实现 CompactDisc
package com.spring.soundsystem;
import org.springframework.stereotype.Component;
@Component("lonelyHeartsClub")
public class SgtPeppers implements CompactDisc …Run Code Online (Sandbox Code Playgroud)