html
<input type="file" #Image accept="image/*"
(change)="handleFileInput($event.target.files)">
Run Code Online (Sandbox Code Playgroud)
.ts 文件
public handleFileInput(files: FileList) {
this.fileToUpload = files.item(0);
console.log(this.fileToUpload);
}
Run Code Online (Sandbox Code Playgroud)
我收到一个 html 错误:
类型“EventTarget”上不存在属性“文件”
我有一个Angular应用程序,其组件是使用angular CLI:ng gc XXX和spec.ts文件生成的。完成项目后,我想编写一些测试文件,但是,当我打开spec.ts文件时,它说“请正确指定tslint的路径”,您知道它有什么问题吗?
我猜可能是因为我将项目移到了桌面上的另一个文件夹吗?单击tslint设置后,我发现tspackage路径是另一个文件夹,我应该将路径更改为当前文件夹吗?
public boolean monkeyTrouble (boolean aSmile, boolean bSmile) {
if (aSmile && bSmile) {
return true;
}
if (!aSmile && !bSmile) {
return true;
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
我不明白为什么最后一行代码应该 return false;
谁能解释一下?谢谢.
我正在为一个简介Java类做一个家庭作业项目,我的任务是创建一个类和方法来测试输入年是否是闰年.我已经看到很多人在一个程序中执行此操作的示例,但我们需要构建该类,然后运行我的教授的Tester文件.我终于得到了所有编译而没有错误,但每次我运行该文件时,我都会被告知这一年是闰年.我尝试了很多不同的东西,我无法弄清楚为什么布尔条件总是评估为真(或者其他任何我做错了).
我的代码如下:
public class Year
{
// declare variable
private int y;
private String year;
// declare constructor
public Year(String theYear, int year_input)
{
y=year_input;
theYear=year;
}
// ensure y has a value
public Year(int y)
{
y=0;
}
// test if y is a leap year
public boolean isLeapYear()
{
if (y%4==0 && (y/100!=0 || y%400==0))
{
return true;
}
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
我教授的代码在这里:
import java.util.Scanner;
public class LeapYearTester{
public static void main(String[] args){
Scanner input = new …Run Code Online (Sandbox Code Playgroud) 这是一个从.txt文件中读取所有内容的简单代码.不确定是什么问题.我尝试了一个不同的测试文件,它只读取了line2和line4 null.它甚至不应该null按照while循环条件读取.
import java.io.*;
import java.util.*;
public class FileInput {
public ArrayList<String> readFile() {
ArrayList<String> content = new ArrayList<>();
try {
File file = new File("input.txt");
BufferedReader br = new BufferedReader(new FileReader(file));
String line = null;
while (br.readLine() != null) {
line = br.readLine();
content.add(line);
System.out.println(line);
}
} catch (FileNotFoundException e) {
System.out.println("File could not be found. " + e.getMessage());
} catch (Exception e) {
System.out.println(e.getMessage());
}
return content;
}
public static void main(String []args) {
FileInput …Run Code Online (Sandbox Code Playgroud) 我如何获得可观察值的发射值而又不触发新发射?我想在ngClass标记中获取可观察值。
我尝试使用管道水龙头来获取通过switchMap传递的值,但没有记录该值。然后,我可以使用trueIfDefinitionsLengthngClass条件。
this.definitions$.pipe(
tap(value => console.log('timer result =', value))
)
Run Code Online (Sandbox Code Playgroud)
观察者订阅| 异步的
模板:
<input [ngClass]="{'input-has-results': trueIfDefinitionsLength > 0}"
[formControl]="searchInput">
<ng-container *ngIf="definitions$ | async as definitions">
<div class="format-options" *ngIf="definitions.length > 0">
<div *ngFor="let definition of definitions" class="search-result">
<div>{{definition.name}}</div>
<div>{{definition.description}}</div>
</div>
</div>
</ng-container>
Run Code Online (Sandbox Code Playgroud)
零件
this.definitions$ = this.searchInput.valueChanges
.pipe(
tap(value => console.log('input')),
//startWith(''),
debounceTime(500),
//distinctUntilChanged(),
switchMap(value => this.definitionService.searchTerm(value))
);
Run Code Online (Sandbox Code Playgroud) 我试图回答另一个问题,这导致我问自己的问题。我做了一些研究,但找不到有关上述主题的任何信息。
我有一个抽象类Character,它有 1 个带有 varargs 参数的抽象方法,如下定义
public abstract class Character {
public abstract void doSomething(int... values);
}
Run Code Online (Sandbox Code Playgroud)
我的印象是任何扩展此类的类都可以使用任意数量的参数覆盖此方法。
// 1st example
public class Player extends Character {
@Override
public void doSomething(int x, int y) { // Two params - do something }
}
// 2nd example
public class NPC extends Character {
@Override
public void doSomething() { // No params - do something }
}
Run Code Online (Sandbox Code Playgroud)
但上面的两个例子都导致了编译时错误。我想知道我在这里错过了什么?上述场景有可能吗?
任何帮助表示赞赏。
在下面的代码中,我尝试将info方法称为供应商.(info方法重载:一个是String,另一个是供应商.)编译器抱怨"方法info(String)不适用于参数Supplier<Double>".我的期望是通过发送供应商对象来调用info方法来获取供应商.我可以帮助理解这个错误吗?
Supplier<Double> randomSupplier = new Supplier<Double>()
{ public Double get()
{ return Math.random(); }
};
logger.info(randomSupplier); <----
Run Code Online (Sandbox Code Playgroud) 我正在尝试将日志从基本的 java maven 项目发送到远程计算机上配置的 Fluent-bit。Fluent-bit 然后会将它们写入文件。这是我的基本java配置。
爪哇
private final static Logger logger = LoggerFactory.getLogger(App.class);
public static void main(String[] args) {
for (int i = 0; ; i++) {
logger.debug("Warn msg");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// do nothing now
}
}
}
Run Code Online (Sandbox Code Playgroud)
和 logback.xml
<appender name="fluentd" class="ch.qos.logback.more.appenders.DataFluentAppender">
<remoteHost>xx.xxx.xxx.xxx</remoteHost>
<port>7777</port>
<encoder>
<pattern>%message%n</pattern>
</encoder>
</appender>
<root level="DEBUG">
<appender-ref ref="fluentd" />
</root>
Run Code Online (Sandbox Code Playgroud)
Fluent位配置:
td-agent-bit.conf
[INPUT]
Name tcp
Listen xx.xxx.xxx.xxx
Port 7777
Parsers_File /etc/td-agent-bit/parsers.conf
Parser custom_parser
[OUTPUT]
Name file
Match * …Run Code Online (Sandbox Code Playgroud) 我一直得到一个java.lang.NumberFormatException.forInputString"9299ff"我需要将它转换为十进制才能使用乘法吗?我不知道为什么我一直收到这个错误.
static BigInteger newP = new BigInteger("9299ff7061bff2d10d9b19653454453d6aed058b5331bea66a4b24e997aca5b6408e050f8e53d99be3f81f563a46b1dbfb51ff739c98f9ad38de2e2d48fdc6ba125604e15f6b76a03e3d64c09bfc7f5c635f80ca55747cf7d0f4839da6ceeb2c43e329021c6fd91f030251ef95180226d50dc1b4395471c69d60a676b263d2bb9f59884914db356bc6fe58d00a999c605a8cf6d246988531ffb79881501383dc092dcb97173c68d2548b7155006b31444cc7ab5c42b57128cd806d02c760e391");
static BigInteger newQ = new BigInteger("a3ec1a1cf64063fd97ad6a24e3509e6d04c36d5be75e3e567b4c713ee6bbbb3bbdcdfb6f89796a6e5d16624ccccff1d154a3b7e5d08a183be9b6e269031224f2d8e454541e22b6a71754a25385b5fdb1b54c69840d6336129d1f02bc39c155a849dfbed96bac2588a50b316499b84430b6104008852ba2b0c09601ca94aa591ff9f31fc6a8df338019e3bb83b5cad61a3bc76dede4d1224aed8c9d7883f8bbcb677164a2138592973af4dbd92bd9e7fcfcc4bbbf19e295bbb6ed14dc5c680311");
final static BigInteger newM = BigInteger.valueOf(65537);
static BigInteger newN = newP.multiply(newQ);
System.out.println(newN);
Run Code Online (Sandbox Code Playgroud) java ×7
angular ×3
boolean ×2
typescript ×2
biginteger ×1
file ×1
fluent-bit ×1
jasmine ×1
java-8 ×1
logback ×1
logging ×1
overriding ×1
photon-os ×1
return ×1
rxjs ×1
supplier ×1
unit-testing ×1