My situation may be one of the reasons, this article provides reference to the old iron
My previous code is part of the getResourceAsStream, and there will be returned to NULL after adding.
Later I executedmvn clean Then take effect

import org.apache.avro.Schema;
import org.apache.avro.generic.GenericData;
import org.apache.avro.generic.GenericDatumReader;
import org.apache.avro.generic.GenericDatumWriter;
import org.apache.avro.generic.GenericRecord;
import org.apache.avro.io.*;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
public class BaseDemon {
public static void main(String[] args) throws IOException {
Schema.Parser parser = new Schema.Parser();
/ / Here is GetResourceAsStream
Schema schema = parser.parse(BaseDemon.class.getResourceAsStream("avro/StringPair.avsc"));
// input
GenericRecord genericRecord = new GenericData.Record(schema);
genericRecord.put("left", "L");
genericRecord.put("right", "R");
ByteArrayOutputStream out = new ByteArrayOutputStream();
DatumWriter<GenericRecord> writer = new GenericDatumWriter<>(schema);
Encoder encode = EncoderFactory.get().binaryEncoder(out, null);
writer.write(genericRecord, encode);
encode.flush();
out.close();
// output
DatumReader<GenericRecord> reader = new GenericDatumReader<>(schema);
Decoder decoder = DecoderFactory.get().binaryDecoder(out.toByteArray(), null);
GenericRecord result = reader.read(null, decoder);
System.out.println(result.get("left"));
System.out.println(result.get("right"));
}
}
To solve this problem is very simple: windows version press the shortcut key alt + shift + ctrl + s mac:command + ; Enter the module configuration, select the module you are using, click sources, crea...
Yesterday I wanted to use getResourceAsStream to get the content of the json file in the resources, and found that it was always null Finally, I changed the uppercase of the first letter of the file n...
background: I have written a springboot+testng project. The project needs to be run through the mvn test command, but the getResourceAsStream method has been reporting errors and cannot run At that ti...
When connecting to the database, I reported this 500, thinking that there was a problem with the server deployment, and then the java code soon created a new Test test connection database. I found tha...
directory structure src:reflect/ReflectTest2.java reflect/resource/config.properties The class's getResourceAsStream is relative to the class loader directory path of the current class. The current pa...
1. Problem description First post my mapping code I encountered a problem when writing the project, that is, the String type data that I return to the front end cannot have a null value, that is, when...
problem: On the windos server, JAVA calls the PYTHON script and the return result is null, but opening cmd runs normally. cmd executes the command: First explain that cmd executes the python command t...
Today I was testing spring mvc to know the character encoding of the request and response of the native servlet, so I wrote two lines of code to test it. This makes me puzzled, why does the request ou...
Why can't 80% of the code farmers can't do architects? >>> Operation of XML in Java, which is the corresponding ELEMENT by specifying the ID. However, only the correct schema and ...